Method: NestedObjects.deep_copy

Defined in:
lib/nested_objects.rb

.deep_copy(data) ⇒ Object

Creates a deep copy of data using Marshal

Examples:

data = { 'a' => { 'b' => [1, 2, 3] } }
NestedObjects.deep_copy(data) #=> { 'a' => { 'b' => [1, 2, 3] } }

Parameters:

  • data (Object)

    The object to be deeply copied

Returns:

  • (Object)

    A new object that is a deep copy of the input obj

Raises:

  • (TypeError)

    if the object cannot be marshaled (see Marshal documentation)



22
23
24
# File 'lib/nested_objects.rb', line 22

def deep_copy(data)
  Marshal.load(Marshal.dump(data))
end