Let’s consider the following code:
class A
@@x = 1
def A.x
return @@x
end
end
class B < A
@@x = 2
end
class C < A
@@x = 3
end
p A.x
3
p B.x
3
p C.x
3
Why do A.x, B.x, and C.x all return 3? The results I would have expected
are: 1, 2, 3. Is this supposed to be this way? Is there a way to get the
results, I expected? Is this a FAQ issue? Did I get it all wrong? BTW, I
use ruby 1.8.1 (2003-12-25) [i386-cygwin].
Regards,
Thomas.