From: John Turner Date: 2006-10-23T20:25:24+09:00 Subject: Re: newbie: class attribute accessors? Diego Virasoro wrote: >> Please explain. Use an example. > >>From what I understood, for any instance variable, I can make ruby > automatically produce the accessors. For example: > > class Dog > @name > @@NumberOfLegs = 4 > > attr_accessor :name > end > > x = Animal.new > ... > puts x.name > > > However, I would like to do something similar for class variables. So > for example in the above example, for @@NumberOfLegs. > > Is this possible? > > Thank you > > Diego Virasoro > You can do this for instance variables of a class, not sure there are equivalents for actual class variables though: class Dog @names = ["Fido", "Rex"] class << self attr_accessor :names end end puts Dog.names