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

some_person.age    # => 25

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

You can even pass in a block. via

This entry was tagged Ruby and tips

comments powered by Disqus

© 2009-2013 All rights reserved. Powered by Pyramid

go to Top