Inspecting the current definition of a method


I’m fairly new to Ruby and this may be a RTFM but I couldn’t find
in books or through a web search:

can one display the current definition of a method and as a step further
one modify it? And if so how?

any pointers?


Phlip wrote:

can one display the current definition of a method

Unfortunately yes. You can use a library called ‘rubynode’ to reflect the
method’s opcodes into a big array of hashes, describing each one.

why unfortunately? because it is not straight forward?

However, Ruby is an extremely dynamic language, and it permits many
tricks using both basic OO programing, and meta-programming techniques
such as define_method. If you call define_method twice, with different
values in the variables around it each time, you can use those variables
inside the new method, and it will vary its behavior each time.

understood. it is precisely one of the reasons that given this
flexibility I
would really like to be able “inspect” what a method in a given context
does. The modification of this behavior would then be an additional
but just the plain seeing what the current definition is would be really
helpful in some cases.

but it seems that this is less straight forward than I have hoped