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

Class Method Details

.deep_merge(hash_a, hash_b) ⇒ Object

Returns a new hash with recursive merge of all keys



20
21
22
23
24
25
26
27
28
# File 'lib/image_optim/hash_helpers.rb', line 20

def deep_merge(hash_a, hash_b)
  hash_a.merge(hash_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



9
10
11
# File 'lib/image_optim/hash_helpers.rb', line 9

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



15
16
17
# File 'lib/image_optim/hash_helpers.rb', line 15

def deep_symbolise_keys(hash)
  deep_transform_keys(hash, &:to_sym)
end