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
===
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,
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,