Allows you to add before
, around
, and after
callbacks to any method.
Add this line to your application's Gemfile:
gem 'method_hooks'
And then execute:
$ bundle
Or install it yourself as:
$ gem install method_hooks
class Model
extend MethodHooks
before :save do
puts 'before'
end
around :save do |method|
puts 'before_around'
method.call
puts 'after_around'
end
after :save, :foo do
puts 'after'
end
def save
puts 'save'
end
def foo
puts 'foo'
end
end
model = Model.new
model.save
model.foo
=begin
Outputs the following:
before
before_around
save
after_around
after
foo
after
=end
- Fork it ( https://github.com/[my-github-username]/method_hooks/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