Module: ImageOptim::HashHelpers
- Defined in:
- lib/image_optim/hash_helpers.rb
Overview
Helper methods to manipulate Hash, mainly used in config
Class Method Summary collapse
-
.deep_merge(a, b) ⇒ Object
Returns a new hash with recursive merge of all keys.
-
.deep_stringify_keys(hash) ⇒ Object
Returns a new hash with all keys of root and nested hashes converted to strings.
-
.deep_symbolise_keys(hash) ⇒ Object
Returns a new hash with all keys of root and nested hashes converted to symbols.
Class Method Details
.deep_merge(a, b) ⇒ Object
Returns a new hash with recursive merge of all keys
18 19 20 21 22 23 24 25 26 |
# File 'lib/image_optim/hash_helpers.rb', line 18 def deep_merge(a, b) a.merge(b) do |_key, value_a, value_b| if value_a.is_a?(Hash) && value_b.is_a?(Hash) deep_merge(value_a, value_b) else value_b end end end |
.deep_stringify_keys(hash) ⇒ Object
Returns a new hash with all keys of root and nested hashes converted to strings
7 8 9 |
# File 'lib/image_optim/hash_helpers.rb', line 7 def deep_stringify_keys(hash) deep_transform_keys(hash, &:to_s) end |
.deep_symbolise_keys(hash) ⇒ Object
Returns a new hash with all keys of root and nested hashes converted to symbols
13 14 15 |
# File 'lib/image_optim/hash_helpers.rb', line 13 def deep_symbolise_keys(hash) deep_transform_keys(hash, &:to_sym) end |