From: "Chr. Rippel" Date: 2002-01-15T12:30:27+09:00 Subject: A possible class variable bug? - Re: a wishlist for ruby 2.0 "Mathieu Bouchard" wrote in .... > * remove Module.constants, which currently calls Object.constants as > Module#constants on the Object object; doing that would uncover the other > Module.constants, that is, Module#constants on the Module object. Well following this logic it might make sense to (re)unfiy the concepts of class variables and global variables the ladder being class variables of the class Object. A somewhat radical version would be the removal of class variables all together since it's possible to simulate the effect of class variables using only class instance variables and class accessory methods (since this has a "pythonish" touch to it surely won't fly;-) In cvs you get ... ------ class A class << self attr_accessor :__var def var A.__var end def var=(rval) A.__var=(rval) end protected :__var end self.__var = "A" def var type.var end end class B < A self.var= "B" end puts A.new.var # => B puts B.new.var # => B ------ In the short term it is probably necessary to clarify the following behavior ----- class Gods @@rule = "Uranus" def ruler puts @@rule end def self.ruler puts @@rule end end module Olympians @@rule ="Zeus" def ruler puts @@rule end end class Titans < Gods @@rule = "Cronus" include Olympians end Gods.new.ruler # => Cronus Gods.ruler # => Cronus Titans.new.ruler # => Zeus Titans.ruler # => Zeus ----- verus ----- class Gods @@rule = "Uranus" def ruler puts @@rule end class << self 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 Gods.new.ruler # => Cronus Gods.ruler # => Cronus Titans.new.ruler # => Zeus Titans.ruler # => Cronus <= here is the difference ----- One possibly would be the introduction of super class variables (I am kidding;-) ----- class Ring_Carrier; end class Narya_Carrier < Ring_Carrier @@@rule ="Gandalf" def rule @@@rule end end class Nenya_Carrier < Ring_Carrier end class Vilya_Carrier < Ring_Carrier end puts Narya_Carrier.new.rule # => Gandalf # Gandalfs demise class Ring_Carrier @@@rule ="One variable to rule them, one variable to find them ...\ and in the darkness bind them." def rule @@@rule end end puts Narya_Carrier.new.rule # => One variable to rule them ... puts Nenya_Carrier.new.rule # => One variable to rule them ... ----- > > * Module#included_modules(recurse=true) where > included_modules(false) would give a list of only _direct_ inclusions. > This is consistent with Module#instance_methods, except for the default > value. A somewhat extend version would be Module#include_modules(recursion_depth = -1) with the "depth" logic of Marshal#depth etc. ... .... /Christoph