The Ruby docs for dup
say:
In general,
clone
anddup
may have different semantics in descendent classes. Whileclone
is used to duplicate an object, including its internal state,dup
typically uses the class of the descendent object to create the new instance.
But when I do some test I found they are actually the same:
class Test
attr_accessor :x
end
x = Test.new
x.x = 7
y = x.dup
z = x.clone
y.x => 7
z.x => 7
So what are the differences between the two methods?