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

djb picture djb · Aug 25, 2011 · Viewed 13.9k times · Source

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?

Answer

Serabe picture Serabe · Aug 25, 2011

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.