From: Gavin Kistner Date: 2006-09-13T01:37:18+09:00 Subject: Re: Duplication from a Subclass, Object#become From: ts [mailto:decoux@moulon.inra.fr] > G> class Foo > G> def dup > G> # strange, magical, important things happen here > G> # which know about all of Foo's instance variables > > You can't use #initialize_copy ? No. In this case, "Foo" is actually REXML::Element. Because these objects store all their attributes in an Attributes instance, a standard (shallow) dup leaves them referencing the same attribute set: irb(main):001:0> require 'rexml/document' => true irb(main):002:0> e1 = REXML::Element.new( 'foo' ) => irb(main):003:0> e1.attributes[ 'bar' ] = 'whee' => "whee" irb(main):004:0> e2 = e1.dup => irb(main):005:0> e2.attributes[ 'la' ] = 'dee da' => "dee da" irb(main):006:0> e1 => 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.