Module Mixin & Class Variables

J

JP Billaud

Hey,

I would like to understand better what happens when one includes a
module with class variables inside a class.

===

module MyModule

@@test = "test"

def self.my_test
puts "From Module"
puts @@test.object_id
end
end

class B
include MyModule

def self.my_test
puts "From Class"
puts @@test.object_id
end
end

B.my_test
MyModule.my_test
From Class
-607833218
From Module
-607833218

===

Doing so, the output shows that in both cases the @@test object is the
same. Does someone have the big picture about class variables look up
while mixin a module inside a class?

Thanks,
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top