From: "David A. Black" Date: 2004-02-14T10:44:04+09:00 Subject: Re: inheritence of class vars Hi -- On Sat, 14 Feb 2004, Ara.T.Howard wrote: > > am i the only one suprised by this? [snip] You must not have been perusing the ruby-talk archive lately :-) It's come up a bunch of times. > i see it, but don't believe it... is it _correct_ to say that: > > iff you want a subclass to have it's own copy of a 'class var' - use > instance vars > > * by 'class var' i mean _not_ an instance var. obviously there are two > types I would say: if you want to maintain state on a per-object basis, use instance variables, including cases where your object is a Class object. Class variables, at least through 1.8.x, are essentially per-hierarchy and not per-Class-object. For 1.9/2.0, though, Matz has presented the following new rules: * class variables will be local to the class/module * if you need to access class variables from outside, define accessors Personally I have mixed emotions about this. There's been so much confusion over the years about class variables vs. instance variables of Class objects, when the two are completely unrelated, and I suspect that making the two things resemble each other more closely will lead to more confusion. (This confusion mainly takes the form, I've observed, of clouding people's perception of the simple and elegant instance variable model.) Then again, I don't know any way around it except to get rid of class variables, which I'm not convinced would be a bad idea (but I know it isn't going to happen :-) David -- David A. Black dblack@wobblini.net