Project

laissez

0.0
No commit activity in last 3 years
No release in over 3 years
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0
 Project Readme

Laissez Build Status

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.

Example:

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"

Why would you want to use this?

  • Lazy configuration
  • Cheap DSLs
  • Cheap method forwarding
  • Defaults that might be destructive

Is this a good idea?

TBD.

Installation

Add this line to your application's Gemfile:

gem 'laissez'

And then execute:

$ bundle

Or install it yourself as:

$ gem install laissez

Contributing

  1. Fork it ( https://github.com/printreleaf/laissez/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Run the tests

$ rake test