Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Module Eval Syntax (http://www.velocityreviews.com/forums/t828131-module-eval-syntax.html)

John W. Long 01-26-2006 08:14 PM

Module Eval Syntax
 
>> class MyModule; end
=> nil
>> MyModule.class_variables

=> []
>> MyModule.module_eval do

?> @@test = true
>> end

=> true
>> @@test

=> true
>> MyModule.module_eval "@@weird = true"

=> true
>> @@weird

NameError: uninitialized class variable @@weird in Object
from (irb):8
>> MyModule.class_variables

=> ["@@weird", "@@test"]
>> Object.class_variables

=> ["@@test"]

What in the world is going on here? Why does the block syntax eval
differently than the string syntax? And why does @@test get defined on
both MyModule and Object?

--
John Long
http://wiseheartdesign.com




All times are GMT. The time now is 10:34 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.