Project

lift

0.01
No commit activity in last 3 years
No release in over 3 years
Hash + Block initialization for easy object construction
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

Lift

Build Status

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!

Installation

Add this line to your application's Gemfile:

gem 'lift'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lift

Usage

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.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/lift/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