From: Gavin Sinclair Date: 2002-12-13T08:50:31+09:00 Subject: Re: Inheritance Question From: "Jim Freeze" > Hi > > I am subclassing the Matrix class, and am having > difficulty getting 'self' for the derived class. > Consider the example below: > > [code snipped] > > include MyMatrix > m = MyMatrix::Matrix[[1,2],[3,4]] > puts m.type > puts m.to_f.inv.type > > === output > MyMatrix::Matrix > Matrix > > How do I get self to be 'MyMatrix' so I can > chain methods, such as: > > m.inv.add_col(c) ? Does "m.inv.add_col(c)" work? The example you give that *doesn't* work involves #to_f. Now I presume this is ::Matrix#to_f ("Ruby in a Nutshell" doesn't mention Matrix#to_f, though), which would be inclined to return a ::Matrix. There's not much you can do about this, except redefine Matrix#to_f to return "self.class.new", if it can be done. Then, you can agitate for this change to be included in the distribution. (I could be barking up the wrong tree, though...) Gavin