Module: DevSuite::Utils::Data::BaseOperations

Included in:
DevSuite::Utils::Data
Defined in:
lib/dev_suite/utils/data/base_operations.rb

Instance Method Summary collapse

Instance Method Details

#deep_delete_key(data, key_to_delete) ⇒ Object

Recursively delete a key from any level in the data structure



8
9
10
11
12
13
14
15
# File 'lib/dev_suite/utils/data/base_operations.rb', line 8

def deep_delete_key(data, key_to_delete)
  case data
  when Hash, Array
    delete_key_from_structure(data, key_to_delete)
  else
    data
  end
end

#deep_merge(hash1, hash2) ⇒ Object

Non-destructive deep merge



28
29
30
# File 'lib/dev_suite/utils/data/base_operations.rb', line 28

def deep_merge(hash1, hash2)
  deep_merge!(hash1.dup, hash2)
end

#deep_merge!(hash1, hash2) ⇒ Object

Destructive deep merge (modifies hash1)



18
19
20
21
22
23
24
25
# File 'lib/dev_suite/utils/data/base_operations.rb', line 18

def deep_merge!(hash1, hash2)
  return hash1 if hash2.nil?

  hash2.each do |key, new_val|
    hash1[key] = merge_value(hash1[key], new_val)
  end
  hash1
end