From: Jason Creighton Date: 2003-07-30T11:15:50+09:00 Subject: Re: Ruby in Ruby On Mon, 28 Jul 2003 19:02:40 GMT "Carl Youngblood" wrote: > > Maybe I'm beeing stupid but I can't see the advantage in doing this other > > than intellectual challenge and interest. Is there any other? > > > > robert > > > > Forgive me if I'm wrong, but I thought that this was required to have > self-evaluating code. In other words, you could store off a segment of code > and call eval() on it and have it run for you on the fly. Isn't some form > of eval() already available? What are its limitations? ~$ ri eval This is a test 'ri'. Please report errors and omissions on http://www.rubygarden.org/ruby?RIOnePointEight ----------------------------------------------------------- Kernel::eval eval( aString [, aBinding [file [line]]]) -> anObject ------------------------------------------------------------------------ Evaluates the Ruby expression(s) in aString. If aBinding is given, the evaluation is performed in its context. The binding may be a Binding object or a Proc object. If the optional file and line parameters are present, they will be used when reporting syntax errors. As of Ruby 1.8, local variables assigned within an eval are only available after the eval if they were defined at the outter scope before the eval executed. In this way eval has the same scoping rules as blocks. def getBinding(str) return binding end str = "hello" eval "str + ' Fred'" #=> "hello Fred" eval "str + ' Fred'", getBinding("bye") #=> "bye Fred" Jason Creighton