Module: Basquiat::HashRefinements
- Defined in:
- lib/basquiat/support/hash_refinements.rb
Instance Method Summary collapse
-
#deep_merge ⇒ self
Merges self with other_hash recursively.
-
#symbolize_keys ⇒ Hash
Symbolize all the keys in a given hash.
Instance Method Details
#deep_merge ⇒ self
Merges self with other_hash recursively
|
# File 'lib/basquiat/support/hash_refinements.rb', line 5
|
#symbolize_keys ⇒ Hash
Symbolize all the keys in a given hash. Works with nested hashes
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/basquiat/support/hash_refinements.rb', line 14 refine Hash do def deep_merge(other_hash) other_hash.each_pair do |key, value| current = self[key] if current.is_a?(Hash) && value.is_a?(Hash) current.deep_merge(value) else self[key] = value end end self end def symbolize_keys each_with_object({}) do |(key, value), new_hash| new_key = begin key.to_sym rescue StandardError key end new_value = value.is_a?(Hash) ? value.symbolize_keys : value new_hash[new_key] = new_value end end end |