Class: Hash
- Inherits:
-
Object
show all
- Defined in:
- lib/i18n/core_ext/hash.rb
Constant Summary
collapse
- MERGER =
proc do |key, v1, v2|
Hash === v1 && Hash === v2 ? v1.merge(v2, &MERGER) : v2
end
Instance Method Summary
collapse
Instance Method Details
#deep_merge!(data) ⇒ Object
25
26
27
|
# File 'lib/i18n/core_ext/hash.rb', line 25
def deep_merge!(data)
merge!(data, &MERGER)
end
|
#deep_symbolize_keys ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/i18n/core_ext/hash.rb', line 12
def deep_symbolize_keys
inject({}) { |result, (key, value)|
value = value.deep_symbolize_keys if value.is_a?(Hash)
result[(key.to_sym rescue key) || key] = value
result
}
end
|
#except(*less_keys) ⇒ Object
8
9
10
|
# File 'lib/i18n/core_ext/hash.rb', line 8
def except(*less_keys)
slice(*keys - less_keys)
end
|
#slice(*keep_keys) ⇒ Object
2
3
4
5
6
|
# File 'lib/i18n/core_ext/hash.rb', line 2
def slice(*keep_keys)
h = self.class.new
keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
h
end
|