From: Sam Roberts Date: 2003-06-24T02:26:08+09:00 Subject: Re: Runtime interpretation [ensemble] ~ $ ri eval ----------------------------------------------------------- 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. def getBinding(str) return binding end str = "hello" eval "str + ' Fred'" #=> "hello Fred" eval "str + ' Fred'", getBinding("bye") #=> "bye Fred" Cheers, Sam Quoteing orion2480@hotmail.com, on Tue, Jun 24, 2003 at 02:21:45AM +0900: > I want to know how to interpret something from a string, so as to be used > directly by the interpreter at runtime. A simplified example: > > $> ruby myprogram.rb > Enter object information:> Array.new(4) > object created:> [nil, nil, nil, nil] > Enter object information:> Hash.new() > object created:> {} > Enter object information:> MyObject.new(2,4,6) > etc., etc. > > I know that, as an interpreted language, Ruby can load new classes, > function definitions, etc. at runtime. But is the above possible? If the > object creation was limited to Arrays and Hash's, it would be simple enough > just to parse the string and go from there... but that severly limits the > funcationality with such specificity. I was hoping to be able to directly > _interpret_ the information in the input string. Is this possible? > > _________________________________________________________________ > MSN 8 with e-mail virus protection service: 2 months FREE* > http://join.msn.com/?page=features/virus > >