Give any class a method called method_called and anytime a method gets called, the method called method_called gets called (heh) with two arguments: a symbol of the method that was called and a binding object of the scope it was called from.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install method_called_hook
class MyClass def self.method_called method_id, scope scope.eval 'do_something' if method_id == :some_method end end
I used this just for its cool factor in my Tamagotchi toy project, but maybe you can find a more useful job for it.
- Fork it ( https://github.com/habibalamin-gems/method_called_hook/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