From: Dreamcat Four Date: 2009-10-12T21:54:37+09:00 Subject: Re: Class Level inheritable attributes - are we there yet? Ah, dreamcat four wrote: > * 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. > I seem to have been wrong about recommending these activesupport/class_inheritable_accessor. They are not fully up to scratch. require "activesupport" class Cartoon self.class_inheritable_accessor :_ self._ = "deputy dawg" def initialize(*args, &block) puts self.class._.inspect puts self._.inspect self._ = "the lazy cat" puts self._.inspect puts self.class._.inspect end end Cartoon.new => "deputy dawg" "deputy dawg" "the lazy cat" "the lazy cat" As you can see, modifying the value in the instantiated object also modifies the value back in the class object. So back to 'clia.rb' like in the first 2 posts. I was maybe going to suggest that we should make a new accessor method. But digging deeper we can see activesupport have already defined 'cattr_accessor' aswell (this time for attributes which aren't inherited and passed on to either instances or subclasses). Then i searched for 'ciattr_accessor' in case someone had already made an inheritable version. http://atomos.rubyforge.org/svn/atomos/lib/extra.rb Does it do the required job? No (is another duplication of cattr). Potential namespace conflict? Yes. David has shown that we should 'extend' and not define any accessor method. So I guess its the better choice (since pointing out about the @=nil). Im definately coming around to understand better and appreciate more David's solution here. Thank you. Best regards, dreamcat4 dreamcat4@gmail.com -- Posted via http://www.ruby-forum.com/.