From: Trans Date: 2006-09-13T22:37:47+09:00 Subject: Re: Duplication from a Subclass, Object#become Phrogz wrote: > Gavin Kistner wrote: > > So, I really want to use Element#clone, but it returns an REXML::Element > > instance when called from my subclass, and I have no control over its > > source code. > > FWIW, I found that I was able to do (typing from memory): > > class Foo < REXML::Element > def clone > klone = self.class.superclass.method( :new ).unbind.bind( > self.class ).call( self ) > # my stuff here > klone > end > end > > ...but I think I'll probably end up re-writing my class to > wrap/delegate to Element, instead of directly inheriting from it. Pity, > from an rdoc standpoint. I have to agree with you. Again and again I use subclassing and it turns out to be more trouble than it's worth. Delegating always seems to be a better course. It seems to me it's sort of like duck typing. Unfortuately delegating means not being able to easily get under the hood of the "super class", e.g. super and instance variables. I wonder it some utility methods could help ease that. T.