[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: eval and dynamic local variable creation in Ruby 1.8 vs 1.9

Yukihiro Matsumoto

6/8/2008 5:18:00 PM

Hi,

In message "Re: eval and dynamic local variable creation in Ruby 1.8 vs 1.9"
on Sun, 8 Jun 2008 19:56:25 +0900, Thairuby Thairuby <kabkab@doramail.com> writes:

|I tested this script with "Try Ruby! (in your browser)"
|(http://tryruby....).
|
|>> RUBY_VERSION
|=> "1.8"
|>> eval "a=1"
|=> 1
|>> a
|=> 1
|
|It is the same as my expectation. But when I try with Ruby 1.9 in my
|computer...
|
|irb(main):001:0> RUBY_VERSION
|=> "1.9.0"
|irb(main):002:0> eval "a=1"
|=> 1
|irb(main):003:0> a
|NameError: undefined local variable or method `a' for main:Object
|...
|
|I read from somewhere that now Ruby can't dynamically create local
|variable. Is it true or just a bug?

The local variables are created in compile time, so that local
variables that are defined in eval() cannot be accessed outside of
eval. In 1.8, irb and tryruby does line by line compilation so that
local variables are spilled from eval(), but in 1.9, it's strictly
prohibited even under line-by-line compilation.

matz.