Help in understanding eval function

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.

thanx in advance.

···

--
Posted via http://www.ruby-forum.com/.

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/\.

Dave Thomas provides as thorough an explanation as you could ask for
in his Ruby Metaprogramming screencasts:

. The fourth one in that series is dedicated to eval, but the first
three are useful in helping you to understand it thoroughly. Also,
David Black does a good job explaining eval (and everything else he
addresses) in The Well-Grounded Rubyist.

···

On Aug 24, 11:55 am, Ravi Kanth <ravi8...@gmail.com> 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.

thanx in advance.
--
Posted viahttp://www.ruby-forum.com/.

7stud -- wrote:

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.

I guess I should explain: the second half of those books is a complete
ruby reference, which as far as I know is the only language reference in
print.

···

--
Posted via http://www.ruby-forum.com/\.

I think that "The Ruby Programming Language" by David Flanagan and
Matz could be fairly considered as a 'language reference'. Personally
I think that David and Matz's style is better suited for experienced
programmers than Dave Thomas's style in Programming Ruby, which I
think is better for beginner/novice programmers.

Gary Wright

···

On Aug 24, 2009, at 3:12 PM, 7stud -- wrote:

Programming Ruby(2nd ed.) for ruby 1.8.x.
Programming Ruby(3rd ed.) for ruby 1.9.x.

I guess I should explain: the second half of those books is a complete
ruby reference, which as far as I know is the only language reference in
print.