From: gabriele renzi Date: 2005-04-21T23:24:31+09:00 Subject: Re: accessor for Class Variable Leonardo Francalanci ha scritto: > I know it's a stupid question, but I can't find the answer... > > Isn't there another way to have an accessor for a class variable than a > "def"??? Something like "attr_reader"? > > class Outing < ActiveRecord::Base > @@planingList = [ "YES", "NO", "YES/NO"] > > def Outing.wind_directionList > return @@wind_directions > end > end > > > If the answer is somewhere in the docs, please point me to it. AFAIK there is not, I think you're supposed to access a class variable directly from instances and class methods, and to generally use a constant when possible, wich is visible from outside. In general the use case for class attributes accessible from the outside is not that much (in my own experience). Anyway you should be able to write them easily with something like (untested): class Class def class_attr sym module_eval "def self.#{sym}() @@#{sym} end" module_eval "def self.#{sym}=(x) @@#{sym}=x end" end end class C class_attr :foo end