From: James Coglan Date: 2008-08-27T18:54:20+09:00 Subject: Re: Difficult Inheritance Problem ------=_Part_14040_8860346.1219831131793 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > Is there a way to define a class level variable that descends down the > inheritance tree unless it is overridden in the same way as this is > possible for methods? I mean I could wrap the data structure in a > method but that does not seem like a very clean solution. Try this, perhaps: class DataObject class << self attr_writer :mapping def mapping @mapping || (self == DataObject ? nil : superclass.mapping) end end end class Page < DataObject; end DataObject.mapping = 'foo' puts Page.mapping #=> 'foo' You could write a class helper to generate these methods. I think Rails has something called 'write_inheritable_attribute' somewhere that does the same thing. ------=_Part_14040_8860346.1219831131793--