inspecting the current definition of a method

  • Thread starter Frank Mittelbach
  • Start date
F

Frank Mittelbach

Hi,

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

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

any pointers?

thanks
frank
 
F

Frank Mittelbach

Phlip said:
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 plus,
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

thanks
frank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,282
Messages
2,571,404
Members
48,096
Latest member
Kenkian2628

Latest Threads

Top