[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

print a method definition from irb?

Seth Cousins

12/8/2007 2:02:00 AM

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

4 Answers

Giles Bowkett

12/8/2007 4:53:00 PM

0

On 12/7/07, Seth Cousins <seth.cousins@gmail.com> wrote:
> Is it possible to reflect the text of a dynamically generated method
> definition?

Not without changing the code which generates the method itself.

That would make a kickass plugin, though.

--
Giles Bowkett

Podcast: http://hollywoodgrit.bl...
Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...
Tumblelog: http://giles....

Bryan Duxbury

12/9/2007 12:24:00 AM

0

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

-Bryan

On Dec 8, 2007, at 8:53 AM, Giles Bowkett wrote:

> On 12/7/07, Seth Cousins <seth.cousins@gmail.com> wrote:
>> Is it possible to reflect the text of a dynamically generated method
>> definition?
>
> Not without changing the code which generates the method itself.
>
> That would make a kickass plugin, though.
>
> --
> Giles Bowkett
>
> Podcast: http://hollywoodgrit.bl...
> Blog: http://gilesbowkett.bl...
> Portfolio: http://www.gilesg...
> Tumblelog: http://giles....
>


Giles Bowkett

12/9/2007 6:58:00 AM

0

On 12/8/07, Bryan Duxbury <bryan@rapleaf.com> wrote:
> Have you tried Ruby2Ruby? It uses ParseTree to translate ruby code in
> memory into ruby code in strings.

Woah.

--
Giles Bowkett

Podcast: http://hollywoodgrit.bl...
Blog: http://gilesbowkett.bl...
Portfolio: http://www.gilesg...
Tumblelog: http://giles....

Seth Cousins

12/9/2007 7:21:00 PM

0

Brilliant, exactly what I was looking for! Thanks, Bryan.

seth

On Dec 8, 2007, at 6:23 PM, Bryan Duxbury wrote:

> Have you tried Ruby2Ruby? It uses ParseTree to translate ruby code
> in memory into ruby code in strings.
>
> -Bryan
>
> On Dec 8, 2007, at 8:53 AM, Giles Bowkett wrote:
>
>> On 12/7/07, Seth Cousins <seth.cousins@gmail.com> wrote:
>>> Is it possible to reflect the text of a dynamically generated method
>>> definition?
>>
>> Not without changing the code which generates the method itself.
>>
>> That would make a kickass plugin, though.
>>
>> --
>> Giles Bowkett
>>
>> Podcast: http://hollywoodgrit.bl...
>> Blog: http://gilesbowkett.bl...
>> Portfolio: http://www.gilesg...
>> Tumblelog: http://giles....
>>
>
>