Duplication from a Subclass, Object#become

I know that this has been discussed before, but searching has not turned
up the definitive answers I had hoped for.

I’m stuck in a situation like this:

class Foo
def dup
# strange, magical, important things happen here
# which know about all of Foo’s instance variables
end
end

class Bar < Foo
def dup
super
end
end

b1 = Bar.new
b2 = b2.dup
p b2.class #=> Foo

How do I get around it? Is subclassing inherently a problem here, and I
need to wrap-and-delegate to a foo instance held by my bar instance?

Will evil.rb ever be part of a standard Ruby distribution, so I could
do:
class Bar < Foo
def dup
klone = super
klone.class = Bar
klone
end
end

“G” == Gavin K. [email protected] writes:

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 ?

G> end

Guy Decoux