# Inspecting the current definition of a method

**URL:** <https://www.ruby-forum.com/t/inspecting-the-current-definition-of-a-method/127902>\
**Category:** Ruby\
**Created:** [February 2, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/inspecting-the-current-definition-of-a-method/127902 "2008-02-02T12:05:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank\_Mittelbach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7ab992/32.png) [@Frank\_Mittelbach](https://www.ruby-forum.com/u/Frank_Mittelbach)\
**Post date:** [February 2, 2008, 12:05pm UTC](https://www.ruby-forum.com/t/inspecting-the-current-definition-of-a-method/127902/1 "2008-02-02T12:05:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Frank\_Mittelbach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7ab992/32.png) [@Frank\_Mittelbach](https://www.ruby-forum.com/u/Frank_Mittelbach)\
**Post date:** [February 3, 2008, 6:58am UTC](https://www.ruby-forum.com/t/inspecting-the-current-definition-of-a-method/127902/2 "2008-02-03T06:58:11Z")

</div>

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  
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
