On Wednesday 16 May 2001 02:11, Joel VanderWerf wrote:
> See p.528 of the pickaxe book (in appendix B).
>
> I guess the difference is that irb parses line by line, but when you
> send a file to ruby it parses the whole thing first. In the latter case,
> the parser does not know that the variable is going to be defined when
> execution reaches that point.

Re: [ruby-talk:15244] Re: Bug or feature? eval("x=5")
Date: Wed, 16 May 2001 07:57:40 -0400
From: W. Kent Starr <elderburn / mindspring.com>
To: ruby-talk / ruby-lang.org
Reply to: elderburn / mindspring.com


On Wednesday 16 May 2001 02:11, Joel VanderWerf wrote:
>ee p.528 of the pickaxe book (in appendix B).
>
> guess the difference is that irb parses line by line, but when you
>end a file to ruby it parses the whole thing first. In the latter case,
>he parser does not know that the variable is going to be defined when
>xecution reaches that point.


Makes sense :-)

FWIW puts eval("x=5") yields expected result (5) in irb, ruby -e and ruby 
test.rb, while eval ("x=5"); puts x fails in ruby -e and test.rb.

puts, of course, forces the eval("x=5") expression to evaluate.

y = eval("x=5"); puts y plays same as puts eval("x=5")

I guess this is more feature than bug, as it forces variable declaration (in 
some form) in file before I send to you :-)

Also, ruby -w test.rb gives warning: eval (...) interpreted as method call, 
even though it correctly evaluates both the puts and y = expressions.

Regards,

Kent Starr
elderburn@mindsp