[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Module Eval Syntax

John W. Long

1/26/2006 8:15:00 PM

>> 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://wiseheart...