Lazy accessors, yo.
Adds lazy_accessor, lazy_reader, and lazy_writer to the Module class. Behaves just like its attr_* counterparts, except if the value is a Proc, the return value of calling the proc is returned instead.
class Person
lazy_accessor :name
end
person = Person.new
person.name # => nil
person.name = proc { "Ron Swanson" }
person.name # => "Ron Swanson"Additionally, you can pass a block to the getter instead, making the = unnecessary.
person.name { "Jean-Ralphio Saperstein" }
person.name # => "Jean-Ralphio Saperstein"- Lazy configuration
- Cheap DSLs
- Cheap method forwarding
- Defaults that might be destructive
TBD.
Add this line to your application's Gemfile:
gem 'laissez'
And then execute:
$ bundle
Or install it yourself as:
$ gem install laissez
- Fork it ( https://github.com/printreleaf/laissez/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
$ rake test