26Blog

I build web applications using Ruby on Rails.
Jan 6 ’11

attr_accessor_with_default

rubyquicktips:

Here’s a method I haven’t seen before: attr_accessor_with_default

This ActiveSupport method allows you to set a default value for an attribute accessor:

class Person
  attr_accessor_with_default :age, 25
end

some_person.age    # => 25

some_person.age = 26
some_person.age    # => 26

You can even pass in a block.

(Source: rubydoc.info)

19 notes (via rubyquicktips & rubyflare)

  1. jonpaullussier reblogged this from bl0ckme
  2. breakbit reblogged this from rubyquicktips and added:
    Nice one, didn’t know this and it’s totally useful. rubyquicktips:
  3. 26blog reblogged this from rubyquicktips
  4. rubyquicktips reblogged this from rubyflare
  5. bl0ckme reblogged this from rubyloveinfo
  6. rubyloveinfo reblogged this from rubyflare
  7. rubyflare posted this