From: "David A. Black" Date: 2003-11-29T12:57:37+09:00 Subject: Re: Class-level readers and writers Hi -- On Sat, 29 Nov 2003, Carl Youngblood wrote: > I've been working with the class attribute shortcuts that Hal introduced > in THE RUBY WAY: > > class Class > def cattr_reader(*syms) > syms.each do |sym| > class_eval <<-EOS > if !defined? @@#{sym.id2name} > @@#{sym.id2name} = nil > end > def self.~{sym.id2name} ^ typo here > I'm having a problem, however, in that classes that are inherited from > the ones in which I declare these attrs don't seem to have them anymore. > Does anyone know how I can make my declared class attributes get > inherited? I ran your code (except for the typo :-) with this added: class A; cattr_accessor(:x); end class B < A; end B.x = 1 puts B.x and it printed 1, so I think the error must be somewhere else. (Just as a footnote, you can also use "normal" accessor shortcuts at the class object level: class A class << self attr_accessor :x end end A.x = 1 # and so on which is implemented with instance variables rather than class variables, if for any reason that suits your purposes better.) David -- David A. Black dblack@wobblini.net