Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > eval and dynamic local variable creation in Ruby 1.8 vs 1.9

Reply
Thread Tools

eval and dynamic local variable creation in Ruby 1.8 vs 1.9

 
 
Thairuby Thairuby
Guest
Posts: n/a
 
      06-08-2008
I tested this script with "Try Ruby! (in your browser)"
(http://tryruby.hobix.com/).

>> 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?
Sorry with my poor english.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Charles Oliver Nutter
Guest
Posts: n/a
 
      06-08-2008
Thairuby Thairuby wrote:
> I read from somewhere that now Ruby can't dynamically create local
> variable. Is it true or just a bug?
> Sorry with my poor english.


In Ruby 1.8, all evals under a given scope (like, at the same scoped
level in a method) used the same shared local variable scope. That scope
grew as needed to accommodate new variables.

In Ruby 1.9, every eval gets its own scope. This provides better
isolation between evals, which has both positive and negative side
effects. On the positive side, the code inside an eval can use a faster
representation of local variables that doesn't depend on being able to
grow. On the negative side, you can't do things like this anymore:

eval "a = 1"
eval "puts a"

- Charlie

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic variable creation from string Massi Python 26 12-13-2011 02:21 PM
Blocks and local variable creation John Lane Ruby 8 04-16-2010 10:26 PM
Different behavior between eval "07" and eval "08" Liang Wang Perl Misc 8 02-02-2008 08:31 PM
DataBinder.Eval and Eval. craigkenisston@hotmail.com ASP .Net 1 06-16-2006 05:33 PM
How to (batch) set EXIF date taken and IPTC creation date and creation time for photos with filenames YYMMDDHHMMSS#.jpg? guercheLE@gmail.com Digital Photography 1 10-04-2005 07:15 PM



Advertisments