Micro library for common pattern of initializing an object with a hash and yielding itself to a block. This pattern is repeated widely across the Ruby ecosystem. I duplicated this code across multiple projects and eventually got sick of it so give you Lift!
Add this line to your application's Gemfile:
gem 'lift'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lift
class Person
include Lift
attr_accessor :name, :email
end
Person.new name: 'adam', email: 'example@example.com'
Person.new name: 'adam' do |adam|
adam.email = 'example@example.com'
end
NOTE: Lift calls super
with no arguments. This is so it can be used in
classes that include modules with their own initialize
method. If an
ancestor's initialize
method takes arguments then you should not use
this library.
- Fork it ( https://github.com/[my-github-username]/lift/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