print a method definition from irb?

S

Seth Cousins

Is it possible to reflect the text of a dynamically generated method
definition?

I'm debugging some ActiveRecord code and it would be very helpful to
dump the text of some of the generated methods. For example, say I
have this:

class Foo < ActiveRecord::Base
has_one :bar
end

AR associations generates a whole host of methods, Foo#bar,
Foo#create_bar, etc., and the exact definitions depend on the options
that I passed to has_one. I can walk through associations.rb and
friends to reconstruct what I think the methods look like but that is
slow and error prone.

There must be an easier way, this is Ruby after all!

Thanks,
seth
 
B

Bryan Duxbury

Have you tried Ruby2Ruby? It uses ParseTree to translate ruby code in
memory into ruby code in strings.

-Bryan
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top