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.

Ravi K. 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"

7stud – wrote:

Ravi K. 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.

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.

I think that “The Ruby P.ming 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 T.'s style in Programming Ruby, which I
think is better for beginner/novice programmers.

Gary W.

On Aug 24, 11:55 am, Ravi K. [email protected] 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/.

Dave T. 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.