Module: MiniI18n::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/mini_i18n/utils.rb

Instance Method Summary collapse

Instance Method Details

#deep_merge(merge_to, merge_from) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mini_i18n/utils.rb', line 11

def deep_merge(merge_to, merge_from)
  merged = merge_to.clone

  merge_from.each do |key, value|
    key = key.to_s

    if value.is_a?(Hash) && merged[key].is_a?(Hash)
      merged[key] = deep_merge(merged[key], value)
    else
      merged[key] = value
    end
  end

  merged
end

#interpolate(string, keys) ⇒ Object


5
6
7
8
9
# File 'lib/mini_i18n/utils.rb', line 5

def interpolate(string, keys)
  string % keys
rescue KeyError
  string
end