From: dreamcat four Date: 2009-10-12T04:34:51+09:00 Subject: Re: Class Level inheritable attributes - are we there yet? On Sun, Oct 11, 2009 at 6:55 PM, Robert Klemme wrote: > Having said that I am not sure that you actually need a language construct > when you can do this: > > > class A >  class <    def foo >      @foo || superclass.foo >    end >  end > It shouldn't be mandated to re-invent the wheel in any programming language, even if its fun style / fun to write. Here is why Robert: because you would have just put 2 bugs into your code. 1) It breaks when you want to set foo = nil in a subclass. 2) Not having an accessor definition will break other code. puts A.instance_variables.inspect => ["@foo"] puts B.instance_variables.inspect => [] puts C.instance_variables.inspect => ["@foo"] Most people would try / expect to fix by putting attr_accessor :foo at top class A. It simply doesn't work and the regular accessor is not inherited. Because in Ruby the Class is instantiated as an instance of object. You could probably imagine a little imaginary OO professor tugging at your clothes and saying 'tut tut, such a shame' or something. And you might argue back that the point was that these aren't bugs if you understand the limitations etc, etc. Just like being back at school eh? But i can assure you when any real programmer in the real world comes along to use your classes and / or modify your code, these holes are eventually surface as real breakages / bugs. Heres my own top 3 recommendations: * Give up / don't use any. Avoid if possible. * Use the activeresource class inheritable accessor. I guess that's not so much of a stretch if you are already depending upon activeresource for other things. * Request a real language implementation in ruby core because class is an object. It would be entirely a matter for the ruby development team to decide whether they would want to implement it, and/or how. I'm very surprised no-one has asked for this on 1.9 line, or to change the existing @@ behaviour since are changed the block level variable scoping and many other things. dreamcat4 dreamcat4@gmail.com