From: "David A. Black" Date: 2008-05-06T00:36:24+09:00 Subject: Re: attr_accessor for class variable? Hi -- On Tue, 6 May 2008, sayoyo Sayoyo wrote: > Hi, > > Is there an equivalent for attr_acessor for the class varialbles? or I > have to write a function each time I wish to exppse the class varaible > to other clasess? In Rails there's a "cattr_*" set of methods that wrap class variables. "cattr" is, in my opinion, a bad choice of name, since it implies that it's representing an "attribute" of an object, whereas class variables are visible to many objects and therefore not suitable for representing attributes. One thing you might consider is creating regular accessor methods for the class object, which will use instance variables belonging to the class: class C class << self attr_accessor :x end end C.x = 1 etc. Unless there's some reason you specifically need class variables, that's a cleaner and more accurate way for a class object to maintain and expose state. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates!