Buy @ Amazon

How to find the method definition - one that is invoked at runtime?


During the QnA session after my talk at RubyConf India 2011, one avid Ruby enthusiast asked me a question, "How to find the method definition - one that is invoked at runtime?".

I confessed that in all my experience (for the last eight and odd months) with Ruby, I have been doing the grep-ing for the method name and then figure out which method definition would be the last to over-ride every other ones declared earlier. No sooner did I finish answering, boooooooooom came a greatly handy tip from a very respectable and renowned geeky person in the crowd - Ola Bini. He adviced to use Ruby's "method" method to figure out the source of the method that was invoked at runtime. What an easier and neater approach!

Hearty thanks to both the folks - one who questioned and the other who answered.

This blog post is my attempt to elaborate more on the tip that Ola Bini had adviced.

Back home after the conference, I googled on these lines and found the following resources useful (in fact, this blog post is only my assimilation of these). May you find them useful.

Additional resources of interest: