Skip to content

Neither #clone nor #dup produce independent Twin copies (changes to one's properties modify all copies' properties) #56

@niels

Description

@niels

On master, as well as at least in versions 0.3.2+, one can neither clone nor duplicate a Twin as expected. Property changes in one of the twins will propagate to all twins.

Setup

class TestTwin < Disposable::Twin
  property :foo
end

original   = TestTwin.new(OpenStruct.new)
cloned     = original.clone
duplicated = original.dup

original.foo = :bar

Expected

original.foo   #=> :bar
cloned.foo     #=> nil
duplicated.foo #=> nil

(I suppose it would be fine if #dup behaved different to #clone, but at least one should achieve the above behaviour and the difference should be documented.)

Actual

original.foo   #=> :bar
cloned.foo     #=> :bar
duplicated.foo #=> :bar

Note that changing the property on either cloned or duplicated will likewise modify it on the other two twins as well. The state of the properties is shared among all twins.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions