From: Kyle Schmitt Date: 2008-09-26T04:30:15+09:00 Subject: Re: Getting the right class with inheritance and super() On Thu, Sep 25, 2008 at 1:31 PM, Robert Klemme wrote: > 2008/9/25 Kyle Schmitt : >> Reading the example you gave, and even some on the net, it looks like >> I'd need the Array class to have a coerce method that can change an >> Array into a FixedSizeArray? > > No. Your coerce method needs to take care. Look at my example. I > did not change Fixnum or Float. Right, you didn't change it, but in the example you're calling coerce on whatever it is that's passed in (perhaps this is the source of my confusion): Class X ... most everything removed ... def + other if self.class === other # fake only self.class.new else #only going to get here if other isn't of class X a, b = other.coerce(self) #doesn't whatever class other is have to have a coerce method? a + b end end end Now if we pull up irb. fixnum=10 float=11.0 hash={} array=[] string="Wax Rabbits" fixnum.respond_to?"coerce" => true float.respond_to?"coerce" => true hash.respond_to?"coerce" => false array.respond_to?"coerce" => false string.respond_to?"coerce" => false So since Arrays Hashes and Strings don't have a coerce, does that mean they can't be used in this fashion? > That's ok but that does not mean that a FixedSizedArray *is an* Array. > I was talking about semantics of inheritance which is usually denoted > *is a* relationship. > > Cheers > > robert Thanks --Kyle