Module: Transformers::Copy
- Defined in:
- lib/transformers/ruby_utils.rb
Class Method Summary collapse
Class Method Details
.deepcopy(value, memo = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/transformers/ruby_utils.rb', line 18 def self.deepcopy(value, memo = {}) key = value.object_id if !memo.key?(key) copy = value.dup memo[key] = copy if value.is_a?(Hash) copy.transform_keys! { |k| deepcopy(k, memo) } copy.transform_values! { |v| deepcopy(v, memo) } elsif value.is_a?(Array) copy.map! { |v| deepcopy(v, memo) } end end memo[key] end |