From: dblack@... Date: 2003-10-13T05:23:46+09:00 Subject: Re: Newbie Class variable question Hi -- On Mon, 13 Oct 2003, Elias Athanasopoulos wrote: > This sounds a little bit wierd to me, since, in the book[*] I have, > the author accesses a class variable implicitly, without having > define self.foo and foo inside the class. Class variables are directly visible only down the class hierarchy: class A @@x = 1 end class B < A puts @@x # 1 end You can give access to them, but you have to do it explicity: class A def self.peek # technically you don't have to call it info :-) @@info end def self.poke(x) @@info = x end end (This is similar to the kind of get/set methods that are often implemented using instance variables, but the resemblance is superficial. Class variables are a different creature, and therfore not a drop-in replacement for instance variables.) Just to try to get it all clear: do you have a page number in The Ruby Way for the example you mentioned? David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav