I want to find a gem or to write a code that implements hooks for methods.
class A
include SomeModule
before_hook :meth, lambda { puts 'bla' }
def meth
puts 'meth'
end
end
# A.new.meth => "bla\nmeth\n"
I am using Rails and I know about callbacks and filters but
meth
isn't an action- I don't wand to change how I method call
Help me please...
UPDATE
I find a gem for automating this code:
include ActiveSupport::Callbacks
define_callbacks :meth_callback
set_callback :meth_callback, :before do |object|
# my code
end
def meth_with_callback
run_callbacks(:meth_callback) { meth }
end
alias_method_chain :meth, :callback