attr_accessor_with_default

Sunday, January 16, 2011

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. via
http://rubyquicktips.tumblr.com/post/2631578325/attr-accessor-with-default

This entry was tagged Ruby and tips

comments powered by Disqus

© 2009-2013 lxneng.com. All rights reserved. Powered by Pyramid

go to Top