From: Joel VanderWerf Date: 2002-11-14T16:23:04+09:00 Subject: Re: Another Newbie question regarding instance variables? Aleksei Guzev wrote: > "montana" wrote in message > news:200211131633.gADGXeFJ000838@buc99.bsd.st... > >>The value of an instance variable is only available to the instance of the > > class, whereas the value of the class variable is available to all instances > of the class? Is this correct? > >>If so the power of an instance variable is then to discern between > > make-ups of similar instances of the same class. > >>Does this sound correct?? >> >>Thanks. >>SA >> > > > The class itself is an object too. It's an instance of some class. As well > as other objects it can have its own variables. Those are called "class > variables" by consideration. But generally they are instance variables too. > You should take a closer look at the notion of metaclasses. Actually, it's clearer to call them "class instance variables". class C @civ = 0 # class instance variable @@cv = 1 # class variable def foo @iv = 2 # instance variable p @civ p @@cv p @iv end end c = C.new.foo # ==> nil because c has no @civ defined # 1 shared by C and c # 2