From: "Wolfgang Nádasi-Donner" Date: 2005-03-15T22:58:22+09:00 Subject: Re: [newby] class variables and class instance variable? -- Wolfgang N�dasi-Donner wonado@donnerweb.de "Florian Gross" schrieb im Newsbeitrag news:39itt7F5tgm5bU1@individual.net... > Wolfgang N�dasi-Donner wrote: > > > The class variable ("@@") belongs to the class object, while the instance > > variable (@) belongs to the instanciated object. A short example. May be you > > want to count how many objects are created based on a class. If you want to > > avoid global variables ($), which is a very good decision, you can use class > > variables. Using instance variables will not work. > > It will. Note that the poster said "class instance variable" which is ***************************************************** Ooops - need new glasses, I believe ;-) - Forget my example, please. I often switch between Ruby an C#. This results in some confusion. ***************************************************** > the instance variable of a Class. Classes are instances of Class and > Class inherits from Module which inherits from Object so classes are > objects as well: > > class Foo > @counter = 0 > class << self > attr_accessor :counter > end > > def initialize() > self.class.counter += 1 > end > end > > Foo.counter # => 0 > 5.times { Foo.new } > Foo.counter # => 5