[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Class-level readers and writers

Carl Youngblood

11/29/2003 2:30:00 AM

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