How to intercept all the calls to a method.
Consider you have a class like this:
p "i'm doing something very interesting"
And you want to execute something before and after the execution of method do_something. How can you do that without touching the current implementation?
Reopen the class, define an alias for dosomething and rewrite dosomething to do the extra stuff.
alias :do_something_new :do_something
p "i'm ready to do something"
p "i did something interesting, isn't it?"
Now if you call do_something you'll have:
service = MyService.new
>> "i'm ready to do something"
>> "i'm doing something very interesting"
>> "i did something interesting, isn't it?"