Possible to get source for arbitrary class?

Is there a way to get a string version (i.e., a "source code"
representation ) of an existing object, such that it could be written to
disk and 'require’ed later, or passed to another process (using perhaps
dRb)?

Thanks,

James

In article CIELJOOMCFBDNHLICOEFKEJACEAA.james@jamesbritt.com,

Is there a way to get a string version (i.e., a "source code"
representation ) of an existing object, such that it could be written to
disk and 'require’ed later, or passed to another process (using perhaps
dRb)?

In TaskMaster I did this by reading a file to be required, stringifying it
and then sending the string to the remote machine and having it required
over there - You might try something similar. I wanted to do what you’re
proposing in your question, but when I asked a similar question some
months ago the answer seemed to be that this was a feature coming in Ruby
2.0. It would be cool to have something like:

sourceString = ClassName.source_code()

Phil

···

JamesBritt james@jamesbritt.com wrote:

In article CIELJOOMCFBDNHLICOEFKEJACEAA.james@jamesbritt.com,

Is there a way to get a string version (i.e., a "source code"
representation ) of an existing object, such that it could be written to
disk and 'require’ed later, or passed to another process (using perhaps
dRb)?

In TaskMaster I did this by reading a file to be required,
stringifying it
and then sending the string to the remote machine and having it required
over there - You might try something similar. I wanted to do what you’re
proposing in your question, but when I asked a similar question some
months ago the answer seemed to be that this was a feature coming in Ruby
2.0. It would be cool to have something like:

sourceString = ClassName.source_code()

Exactly. I haven’t looked at TaskMaster until the Dobbs article (lack of
time, not lack of interest) and in the meantime wrote a class that packages
marshaled objects with the object’s source. I’ve looked at various was of
snarfing the class source though none of them strike me as completely
portable or elegant. The essence of it is, the literal source isn’t really
the concern, but just enough of a representation such that another Ruby
process can know enough about an object to restore it from a marshaled
state.

Thanks for the info.

James

···

JamesBritt james@jamesbritt.com wrote:

Phil