Gavin Kistner
9/12/2006 4:17:00 PM
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