Search code examples
rubyirb

In IRB, can I view the source of a method I defined earlier?


If I define a method in IRB, is there any way to review its source later in the session?

> def my_method
>   puts "hi"
> end

Several screens of output later I'd like to be able to write something like

> source my_method

and get back:

=> def my_method; puts "hi"; end;

Is this possible?


Solution

  • Try pry. There is a railscast about it (released this same week!) and it shows you how to show the code by using show-method.