The basic idea is this:
module Mst
def self.included(base)
# define a method on base using define_method named :before, which takes an
# argument and a block
# in that method, you grab the method with that name, using .method()
# you then define a new method, named method, which calls the block and
# then calls the original method
end
end
class Foo
include Mst
def test
puts "test"
end
before :test do
puts "before"
end
end
Module named after you. You can see how the logic only changes a bit for after and around. You could then wrap this up as a library, and all you'd need to do is the include.http://api.rubyonrails.org/classes/ActiveSupport/Callbacks/F... has an example, I think.