Module: I18n::Utils

Defined in:
lib/i18n/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deep_merge(hash, other_hash, &block) ⇒ Object



18
19
20
# File 'lib/i18n/utils.rb', line 18

def deep_merge(hash, other_hash, &block)
  deep_merge!(hash.dup, other_hash, &block)
end

.deep_merge!(hash, other_hash, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/i18n/utils.rb', line 22

def deep_merge!(hash, other_hash, &block)
  hash.merge!(other_hash) do |key, this_val, other_val|
    if this_val.is_a?(Hash) && other_val.is_a?(Hash)
      deep_merge(this_val, other_val, &block)
    elsif block_given?
      yield key, this_val, other_val
    else
      other_val
    end
  end
end

.deep_symbolize_keys(hash) ⇒ Object



34
35
36
37
38
39
# File 'lib/i18n/utils.rb', line 34

def deep_symbolize_keys(hash)
  hash.each_with_object({}) do |(key, value), result|
    result[key.respond_to?(:to_sym) ? key.to_sym : key] = deep_symbolize_keys_in_object(value)
    result
  end
end

Instance Method Details

#except(hash, *keys) ⇒ Object



7
8
9
# File 'lib/i18n/utils.rb', line 7

def except(hash, *keys)
  hash.except(*keys)
end