The beauty of metaprogramming in attr_accessor_with_default

Wrote at January 06, 2010 da Filippo Camillo

attr_accessor is one of the beauty of ruby lang. Attr_accessor_with_default is an ActiveSupport’s Module extension very useful.

For example, you can give attribute :profiled the initial value true:

You can also give attribute a dynamic default value (scope of self). I think that this is more better than use inizialize.

source: http://railsapi.com/doc/v2.3.2/classes/Module.html#M000043

no comment yet

Add a comment