From: Stephen Bannasch Date: 2006-04-11T07:36:26+09:00 Subject: Re: class variables and inheritance (ActiveRecord problem) I realized after working more that cattr_accessor was defined in the core extensions in ActiveSupport as an extension of the class Class. I now working on understanding how this works: # Extends the class object with class and instance accessors for class attributes, # just like the native attr* accessors for instance attributes. class Class # :nodoc: def cattr_reader(*syms) syms.flatten.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} @@#{sym} = nil end def self.#{sym} @@#{sym} end def #{sym} @@#{sym} end EOS end end def cattr_writer(*syms) syms.flatten.each do |sym| class_eval(<<-EOS, __FILE__, __LINE__) unless defined? @@#{sym} @@#{sym} = nil end def self.#{sym}=(obj) @@#{sym} = obj end def #{sym}=(obj) @@#{sym} = obj end EOS end end -- - Stephen Bannasch Concord Consortium, http://www.concord.org