tap + instance_eval
Add this line to your application's Gemfile:
gem 'flap'
And then execute:
$ bundle
Or install it yourself as:
$ gem install flap
require "flap"
hash = {a: 1, b: 2}
# w/o flap
ret = hash.dup.tap {|h| h.delete(:a) }
p hash #=> {:a => 1, :b => 2}
p ret #=> {:b => 2}
# w/ flap
ret = hash.dup.instance_eval_tap { delete :a }
p hash #=> {:a => 1, :b => 2}
p ret #=> {:b => 2}
You can also use short version of methods.
Flap.enable_short_methods!
hash = {a: 1}
hash.itap { delete :a } #=> {}
- Fork it ( http://github.com/hekk/flap/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 new Pull Request