Module Eval Syntax

J

John W. Long

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top