Module: ActiveTools::CoreExtension::DeepCopy::HashExtension
- Defined in:
- lib/active_tools/core_extension/deep_copy.rb
Overview
Return the ‘deep’ brand new copy of Hash, Array or Set. All nested hashes/arrays/sets rebuilded at the same way.
Instance Method Summary collapse
Instance Method Details
#deep_copy(&block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/active_tools/core_extension/deep_copy.rb', line 8 def deep_copy(&block) self.class.new.tap do |new_hash| each do |k, v| new_hash[k] = case v when Hash, Array, Set then v.deep_copy(&block) else block_given? ? yield(v) : v.dup rescue v end end end end |