[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Method to view a class or a method?

Vincent Foley

4/11/2006 3:03:00 PM

Hello everyone,

I was writing some code in irb this morning, and after a while, I
realized that I wanted to put that into a script. I had to go and copy
& paste every method by hand. I was wondering if there was a way to
get the source string of a class (or possibly, just a method)? Kind of
like the reverse of eval(). I know that some languages support this
feature (Forth and Factor come to mind).

Thanks

3 Answers

Robert Klemme

4/11/2006 3:54:00 PM

0

Vincent Foley wrote:
> Hello everyone,
>
> I was writing some code in irb this morning, and after a while, I
> realized that I wanted to put that into a script. I had to go and copy
> & paste every method by hand. I was wondering if there was a way to
> get the source string of a class (or possibly, just a method)? Kind of
> like the reverse of eval(). I know that some languages support this
> feature (Forth and Factor come to mind).

No. The closest you get is methods with signature length. If you want
the full source code you need to do additional tricks, i.e. parse the
code yourself (probably using any of the ruby parsers around) before
ruby sees it.

That's the reason why I usually do it the other way round: I write the
code in an editor and paste it to IRB. :-)

Kind regards

robert

Chris Hulan

4/11/2006 5:36:00 PM

0


Vincent Foley wrote:
> Hello everyone,
>
> I was writing some code in irb this morning, and after a while, I
> realized that I wanted to put that into a script. I had to go and copy
> & paste every method by hand. I was wondering if there was a way to
> get the source string of a class (or possibly, just a method)? Kind of
> like the reverse of eval(). I know that some languages support this
> feature (Forth and Factor come to mind).
>
> Thanks

Maybe you should look at using irb-history
(http://irb-history.rubyforge...)
Not familiar with it, but looks like it will save and allow recall of
code entered in an IRB session

Cheers

S.Volkov

4/12/2006 9:05:00 AM

0

Robert Klemme wrote:
>..

> That's the reason why I usually do it the other way round: I write the
> code in an editor and paste it to IRB. :-)
Do you mean copy/paste? Why!!!
There are Emacs, Eclipse, Crimson Editor... lot of others, which allow you
to execute script from editor buffer while you are editing it, and if you
need to test few lines of code, just add them in the editor buffer and put
__END__ line after, or use =begin/=end to prevent execution of unfinished
code; Emacs even allows you to send text to irb session from emacs buffer;
you should try - you will like it!
regards
Sergey