From: "Chr. Rippel" Date: 2002-02-08T00:03:47+09:00 Subject: Class variable bug It seems that the following class variable bug feel through the reporting cracks - the problem is that the two different class method definition styles potentially effect the visibility of class variables in conjunction with mixins in subclasses. class A @@var = nil class << self def first_form; @@var end end def self.second_form; @@var end end The following longish example illustrates this bug (1.6.5 & cvs). It is worthwhile to point out that once this situation is resolved then including modules becomes a valuable(don't know?) idiom for ``invalidating class variables'' in the subclass hierarchy. ---- class Gods @@rule = "Uranus" def ruler puts @@rule end def self.ruler # <= per method definition style puts @@rule end end module Olympians @@rule ="Zeus" def ruler puts @@rule end end class Titans < Gods @@rule = "Cronus" include Olympians end Atlas = Titans.new Gods.new.ruler # => Cronus Gods.ruler # => Cronus Atlas.ruler # => Zeus Titans.ruler # => Zeus # <= I like this better ----- versus ----- class Gods @@rule = "Uranus" def ruler puts @@rule end class << self # <= multiple method definition style def ruler puts @@rule end end end module Olympians @@rule ="Zeus" def ruler puts @@rule end end class Titans < Gods @@rule = "Cronus" include Olympians end Atlas = Titans.new Gods.new.ruler # => Cronus Gods.ruler # => Cronus Atlas.ruler # => Zeus Titans.ruler # => Cronus <= here is the difference # extended example def Atlas.ruler puts @@rule end Atlas.ruler # => Zeus class Gods def Atlas.ruler puts @@rule end end Atlas.ruler # => Zeus ---- /Christoph