Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/alula/monkey_patches.rb
Instance Method Summary collapse
-
#deep_dup ⇒ Object
should only be used for deeply nested structures.
Instance Method Details
#deep_dup ⇒ Object
should only be used for deeply nested structures
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/alula/monkey_patches.rb', line 28 def deep_dup case self when Numeric, Symbol, NilClass, TrueClass, FalseClass self # Immutable types don't need duplication when String dup when Array map(&:deep_dup) when Hash each_with_object({}) do |(key, value), duped| duped[key.deep_dup] = value.deep_dup end else # Fall back to the original dup method # Should NOT use marshalling/unmarshalling as this can lead to arbitrary code execution based on user input. begin dup rescue StandardError self end end end |