From: Tommy Nordgren Date: 2008-10-17T12:49:11+09:00 Subject: Re: instance counter On Oct 17, 2008, at 5:36 AM, Pierre Lebrun wrote: > Please forgive the trite nature of this question, I'm new to ruby > and OO > programming in general. I'm looking to create a counter that keeps > track > of the number of instances created from one class (++ would we access > this from the class or the instace?). > > I've made a few lame attempts myself so far but nothing functional :-P > > Also, why does ruby return an error for: > > Class Bob > attr_reader :count > @count = 0 > def initialize > @count += 1 > end > end > > Cheers! > -- > Posted via http://www.ruby-forum.com/. > You need to write @@count = 0. and def Bob.count return @@count end ------ What is a woman that you forsake her, and the hearth fire and the home acre, to go with the old grey Widow Maker. --Kipling, harp song of the Dane women Tommy Nordgren tommy.nordgren@comhem.se