Module: Contrast::Utils::HashUtils
- Defined in:
- lib/contrast/utils/hash_utils.rb
Overview
Module to hold various hash utils methods
Class Method Summary collapse
-
.deep_symbolize_all_keys(value) ⇒ Hash
Deep symbolizes all keys.
-
.precedence_merge(hsh, other_hsh) ⇒ Object
Merges two hashes, first hash will preserve it’s values and will only add unique values.
-
.precedence_merge!(hsh, other_hsh) ⇒ Hash
Merges two hashes, first hash will preserve it’s values and will only add unique values.
Class Method Details
.deep_symbolize_all_keys(value) ⇒ Hash
Deep symbolizes all keys
41 42 43 44 45 |
# File 'lib/contrast/utils/hash_utils.rb', line 41 def deep_symbolize_all_keys value new_hash = {} value.each { |key, v| new_hash[key.to_sym] = map_value(v) } new_hash end |
.precedence_merge(hsh, other_hsh) ⇒ Object
Merges two hashes, first hash will preserve it’s values and will only add unique values.
13 14 15 16 17 18 19 20 21 |
# File 'lib/contrast/utils/hash_utils.rb', line 13 def precedence_merge hsh, other_hsh hsh.merge(other_hsh) do |_key, old_value, new_value| if old_value.is_a?(Hash) || new_value.is_a?(Hash) Contrast::Utils::HashUtils.precedence_merge(old_value, new_value) else old_value end end end |
.precedence_merge!(hsh, other_hsh) ⇒ Hash
Merges two hashes, first hash will preserve it’s values and will only add unique values.
28 29 30 31 32 33 34 35 36 |
# File 'lib/contrast/utils/hash_utils.rb', line 28 def precedence_merge! hsh, other_hsh hsh.merge!(other_hsh) do |_key, old_val, new_val| if old_val.is_a?(Hash) || new_val.is_a?(Hash) Contrast::Utils::HashUtils.precedence_merge!(old_val, new_val) else old_val end end end |