Class: Object

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

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


14
15
16
# File 'lib/symbolized/core_ext/object/deep_dup.rb', line 14

def deep_dup
  duplicable? ? dup : self
end

#duplicable?Boolean

Can you safely dup this object?

False for nil, false, true, symbol, number and BigDecimal(in 1.9.x) objects; true otherwise.

Returns:

  • (Boolean)


25
26
27
# File 'lib/symbolized/core_ext/object/duplicable.rb', line 25

def duplicable?
  true
end