Class: Object

Inherits:
BasicObject
Defined in:
lib/core_ext/deep_dup.rb,
lib/core_ext/duplicable.rb

Overview

Instance Method Summary collapse

Instance Method Details

#deep_dupObject

Returns a deep copy of object if it’s duplicable. If it’s not duplicable, returns self.

object = Object.new
dup    = object.deep_dup
dup.instance_variable_set(:@a, 1)

object.instance_variable_defined?(:@a) # => false
dup.instance_variable_defined?(:@a)    # => true


13
14
15
# File 'lib/core_ext/deep_dup.rb', line 13

def deep_dup
  duplicable? ? dup : self
end

#duplicable?Boolean

Can you safely dup this object?

False for method objects; true otherwise.

Returns:

  • (Boolean)


8
9
10
# File 'lib/core_ext/duplicable.rb', line 8

def duplicable?
  true
end