Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/core_ext/deep_dup.rb,
lib/core_ext/duplicable.rb
Overview
Instance Method Summary collapse
-
#deep_dup ⇒ Object
Returns a deep copy of object if it’s duplicable.
-
#duplicable? ⇒ Boolean
Can you safely dup this object?.
Instance Method Details
#deep_dup ⇒ Object
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.
8 9 10 |
# File 'lib/core_ext/duplicable.rb', line 8 def duplicable? true end |