From: Logan Capaldo Date: 2006-05-21T13:04:01+09:00 Subject: Re: Class variables and class instance variables in Pickaxe 2nd On May 20, 2006, at 11:52 PM, uncutstone wu wrote: > These are two concepts in Pickaxe 2nd edtion. > > Class Variables example is in chapter 3: > > class Song > @@plays = 0 > def play > @@plays += 1 > end > end > > Class instance variables example is in chapter 24: > > class Test > @cls_var = 123 > def Test.inc > @cls_var += 1 > end > end > > The only difference I can see is the names of the variables, one > begins > with @, and the other begins with @@. > Are they same? I feel confused if they are same , why give two > names? > > Thanks in advance. > > uncutstone > > -- > Posted via http://www.ruby-forum.com/. > Class variables are accessible to instances of the class directly. Class variables also propagate thru the inheritance hierarchy. Class instance variables are just like any other instance variables, they just happen to be associated with an object of class Class.