From: Rick DeNatale Date: 2007-03-03T03:57:02+09:00 Subject: Re: Newbie Question On 3/2/07, Brian Candler wrote: > On Fri, Mar 02, 2007 at 08:10:10AM +0900, james.d.masters@gmail.com wrote: > > > Go back and look at my earlier post... > > > > OK, I did... and I also ran the code that you provided in the second > > example. I really do understand the concept of class instance > > variables. But I'm trying to show how they can be preset and have the > > preset values inherited. > > Maybe this is where the confusion arises. Here you're talking about > inheritance of *values*, which implies the value from class A is *copied* to > class B. The trouble with that approach is, when exactly do you copy the > values? When class B is first created? But that assumes that class A has > already set its instance variable. If it hasn't, then there's nothing for > class B to copy. > > That's why my suggestion was to set the value in the class's own instance > variable space only, and not copy it, but at the point when you *read* the > value, if you don't have it in your own instance variable space then walk > upwards. It seems like this is approaching the notions of delegation rather than inheritance. Some years ago there was a raging debate over delegation vs. inheritance in the OO community. (Do a google search on oopsla delegation inheritance). Some languages unified instance variables with methods. Self did this. Self had no explicit classes, objects have named slots which contain values, some of which are executable. And these named slots were resolved by walking up a chain of objects (rather than having a superclass you delegate to another object). Ruby actually uses somewhat similar mechanisms, but it separates methods from instance variables, it puts the tables which are used to find methods into a class rather than in the instance itself (even for singleton methods which get put in singleton classes). Although Ruby instance variables are implemented by name lookup in an instance variable table owned by the instance, there's no instance chaining so there's no place to search upwards for instance variables. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/