J
JP Billaud
I am using Ruby 1.8.7 and I bumped into a weird behavior regarding
eigenclass of Class object.
Below, I am declaring a class variable inside the eigenclass of Class A.
However for some reasons when I print out the class variables of A and
B, it seems the class variable @@test is accessible for both.
===
def eigen
class << self
self
end
end
class A
end
class B
end
egA = A.send :eigen
puts egA.object_id
egB = B.send :eigen
puts egB.object_id
egA.class_eval do
@@test = 5
end
puts "A Class Variables"
puts A.class_variables
puts "B Class Variables"
puts B.class_variables
===
Any idea?
Thanks,
eigenclass of Class object.
Below, I am declaring a class variable inside the eigenclass of Class A.
However for some reasons when I print out the class variables of A and
B, it seems the class variable @@test is accessible for both.
===
def eigen
class << self
self
end
end
class A
end
class B
end
egA = A.send :eigen
puts egA.object_id
egB = B.send :eigen
puts egB.object_id
egA.class_eval do
@@test = 5
end
puts "A Class Variables"
puts A.class_variables
puts "B Class Variables"
puts B.class_variables
===
-607970628
-607970668
A Class Variables
@@test
B Class Variables
@@test
Any idea?
Thanks,