From: Ralph Shnelvar Date: 2009-11-28T22:00:57+09:00 Subject: Re: Class variables, instance variables, singleton; Ruby v. C++ DAB> And of course this is one of the (many) problems with class variables: DAB> they make obscure the otherwise rather simple notion that classes can DAB> have instance variables because classes are objects and any object can DAB> have instance variables. David ... this may be the higher-level gestalt that I was missing. It sure sounds like it. Let me flesh out my questions/comments about this paragraph so that you and others have something specific to answer. Let's call the classed F & G. (1) OK, classes are (i) objects; (ii) are executable code. (2) If I do the following class F end f = F.new F.class # class f.class # F this makes sense to me. What (relevant and important conceptually) messages (other than "new") can I send to a class? But see (3), below. (3) class F def sub1 @@x = 1 end end class G self.sub1 @@x=2 end end # Why? Didn't the interpreter "see" @@x in class F? F.class_variables # [] # makes sense G.class_variables # ["@@x"] f = F.new # Why? Shouldn't the method inherit from the class? f.class_variables # undefined method f.sub1 # 1 # makes sense. class variable now explicitly executed F.class_variables # ["@@x"] # How to use class_variable_get if the method is private??? F.class_variable_get(:@@x) # error private method! OK, that should do it for now.