help in understanding eval function

R

Ravi Kanth

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

7stud --

Ravi said:
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"
------------------
 
7

7stud --

7stud said:
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.
 
G

Gary Wright

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 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
 
I

imdwalrus

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.

Dave Thomas provides as thorough an explanation as you could ask for
in his Ruby Metaprogramming screencasts:
http://www.pragprog.com/screencasts/v-dtrubyom/the-ruby-object-model-and-metaprogramming
.. 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top