G
Gavin Kistner
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 =3D Bar.new
b2 =3D b2.dup
p b2.class #=3D> 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 =3D super
klone.class =3D Bar
klone
end
end
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 =3D Bar.new
b2 =3D b2.dup
p b2.class #=3D> 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 =3D super
klone.class =3D Bar
klone
end
end