From: Jim Freeze Date: 2002-12-15T00:27:58+09:00 Subject: Re: Inheritance Question On Saturday, 14 December 2002 at 22:00:53 +0900, ts wrote: > >>>>> "J" == Jim Freeze writes: > > J> Don't you mean that this is how Array was implemented, not what > > Vect and Matrix are implemented via Array. It can be strange if Vect do > something and Array do another thing. cat v.rb require 'matrix' v1 = Vector[1] v2 = Vector[2] p ((v1+v2).class) ruby v.rb Vector Here, Vector extends array and returns a Vector and NOT Array when adding two Vectors. I don't see why an extension of Matrix should not return the super class. Same for Array. > J> The language doesn't force one to always return the base class. > > I know this but there are other classes in ruby which do like Array (don't > remember actually but this seems to be a voluntary choice) I agree that in general, it would be difficult to ensure that every library returns self for chainable methods. But, I do think it is a good practice, especially if you expect your class to used as a base class. For the case of Matrix, it makes it impracticle to be used as a base class. To extend the class, I would have to do it directly and hope that I don't cause any problems. But when I am writing numerical code, I usually have accuracy as my primary goal, so I am unlikely to extend the class directly because it may have side effects. -- Jim Freeze