From: Nathan Date: 2009-10-14T06:15:10+09:00 Subject: Re: Class Level inheritable attributes - are we there yet? On 2009-10-13 14:57:25 -0400, Robert Klemme said: > On 13.10.2009 20:07, Dreamcat Four wrote: >> Robert Klemme wrote: >>> My understanding of the above is this. You have two use cases in mind: >>> >>> 1. Inheriting dynamic attribute values defining a proximity rule, i.e. >>> when asked you get the closest attribute. >> >> Yes. I have been using this way for the YamlDoc Gem >> >>> 2. Constants which with the same proximity lookup rule as above only >>> that values do not change after the initialization. >> >> No. I dont suggest that. > > Well, it _is_ in the language already. I prefer the constant way: class A Foo = 2 def self.foo self::Foo end end class B < A; end class C < A Foo = 4 end class D < C; end class E < D Foo = 6 end [A, B, C, D, E].map { |k| k.foo } # => [2, 2, 4, 4, 6] I would vote that @@ be changed to be treated in the same way constants are now (or even to be a getter/setter for a constant of the same name), stored in original and looked up in the chain, that way they can be overriden locally but don't need to be _forcefully copied_ down into each and every class. Deep (or any other) copy doesn't seem like a good idea at all to me. -- Nathan