Class-level readers and writers

C

Carl Youngblood

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}
@@#{sym}
end
EOS
end
end

def cattr_writer(*syms)
syms.each do |sym|
class_eval <<-EOS
if !defined? @@#{sym.id2name}
@@#{sym.id2name} = nil
end
def self.#{sym.id2name}=(obj)
@@#{sym.id2name} = obj
end
EOS
end
end

def cattr_accessor(*syms)
cattr_reader(*syms)
cattr_writer(*syms)
end
end

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?

Thanks,
Carl Youngblood
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top