Hi, it seems that “dup” method is not recursive, so if we do:
obj_b = obj_a.dup
then all the attributes of obj_b will be a exact copy of attributes of
obj_a, and not references.
But if an attribute of obj_a is an object containing objects inside
then those will be referenced and not copied. This is:
obj = Obj.new
obj.kk = “KAKA1”
=> #<A:0xb7bf6de8 @att=#<Obj:0xb7c0dcf0 @kk=“KAKA1”>>
=> #<A:0xb7becd97 @att=#<Obj:0xb7c0dcf0 @kk=“KAKA1”>>
=> #<A:0xb7bf6de8 @att=#<Obj:0xb7c0dcf0 @kk=“KAKA2”>>
So finally, an attribute of an attribute of “a” is been modified when
I know that I should personalize “dup” method for class A, but is not
any other way? Does exist any automatic way of doing it?
I expect some method “dup_recursive” that looks for objects into
attributes recursively and clones them instead of reference.
Is there something as it?
Thanks a lot.