From: Luke Kanies Date: 2005-07-12T09:53:44+09:00 Subject: Re: class_attr_accessor On Tue, 12 Jul 2005, Jeffrey Moss wrote: > The @@class_var syntax is unique in that you can assign a value to a class > and it is propogated down. Yep, I know, and I almost never use this type of variable. > With class instance vars, class << self; attr_accessor :class_var; end > this will only give you a "slot", you still have to populate the slot with > something. So for a subclass to inherit values, it would need to have > something populating the subclasses values each time the class is inherited > presumably in the "inherited" method or manually as in Ara's "init" method. > The same goes for an instance attribute, it needs to be initialized in the > initialize method, presumably, you can't assign defaults with the > attr_accessor method. Yeah, I know how the variable type behaves; as I said, I'm using tons of them. In my case, I've got classes set up that are perfectly functional with only class instance variables defined, but they can define extra methods if they want. For instance: # an abstract base class class Base def self.dostuff unless defined? @data raise "Data must be defined end ... do stuff ... end end class Sub < Base @data = %w{this is data} end class OtherSub < Base @data = %w{this is more data} end I use this basic construct over and over, but I'm using it almost to death in my current project which is right about 10k lines now. -- One of the Ten Commandments for Technicians (7) Work thou not on energized equipment, for if thou dost, thy fellow workers will surely buy beers for thy widow and console her in other ways. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://config.sage.org