Method: Origami::Object#copy

Defined in:
lib/origami/object.rb

#copyObject

Deep copy of an object.



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/origami/object.rb', line 457

def copy
    saved_doc = @document
    saved_parent = @parent

    @document = @parent = nil # do not process parent object and document in the copy

    # Perform the recursive copy (quite dirty).
    copyobj = Marshal.load(Marshal.dump(self))

    # restore saved values
    @document = saved_doc
    @parent = saved_parent

    copyobj.set_document(saved_doc) if copyobj.indirect?
    copyobj.parent = parent

    copyobj
end