[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ruby reflection of methods

Ray Case

1/8/2008 3:37:00 AM

If I do something like:
meth=method(:send) (or any other method)

is there anyway to get the actual text of the send method? like
meth.body or something?

I don't actually need the text of the method, I was just wondering.

Ray
1 Answer

Giles Bowkett

1/8/2008 3:47:00 AM

0

> If I do something like:
> meth=method(:send) (or any other method)
>
> is there anyway to get the actual text of the send method? like
> meth.body or something?
>
> I don't actually need the text of the method, I was just wondering.

There is such a way. Use the mighty and impressive Ruby2Ruby gem. It's
downright scary.

teh IRB session:

>> class RedWine
>> def drink
>> "glug"
>> end
>> end
=> nil
>> @red_wine = RedWine.new
=> #<RedWine:0x1108514>
>> require 'ruby2ruby'
=> true
>> @red_wine.method(:drink).to_ruby
=> "def drink\n "glug"\nend"

--
Giles Bowkett

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