From: 7stud -- Date: 2009-08-25T04:10:57+09:00 Subject: Re: help in understanding eval function Ravi Kanth wrote: > Hi > I am new to ruby I am having trouble in understanding the eval function > > can you suggest me a good reference to look at the various classes and > methods available. > > Programming Ruby(2nd ed.) for ruby 1.8.x. Programming Ruby(3rd ed.) for ruby 1.9.x. or... $ri eval ------------------------------------------------------------ Kernel#eval eval(string [, binding [, filename [,lineno]]]) => obj ------------------------------------------------------------------------ Evaluates the Ruby expression(s) in _string_. If _binding_ is given, the evaluation is performed in its context. The binding may be a +Binding+ object or a +Proc+ object. If the optional _filename_ and _lineno_ 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" ------------------ -- Posted via http://www.ruby-forum.com/.