how can I dynamically get the source of an object's method?

D

David Lowenfels

Hello:

I've been wondering if it's possible to get an object to print out the
source code of a method into a string.

It seems like it _should_ be possible, but it's kind of a wacky idea. I
haven't seen it mentioned anywhere.

Thanks in advance,
David
 
J

James Edward Gray II

I've been wondering if it's possible to get an object to print out the
source code of a method into a string.

This isn't easy in the general sense with Ruby, because you can use
code to write, or even change, code.

However, some of the tricks for the SerializableProc Ruby Quiz might
give you ideas:

http://www.rubyquiz.com/quiz38.html

See Florian Gross's solution, for example.

James Edward Gray II
 

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
474,219
Messages
2,571,117
Members
47,727
Latest member
PasqualePf

Latest Threads

Top