Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/omniconf/helpers.rb
Instance Method Summary collapse
- #recursive_merge!(with_hash) ⇒ Object
-
#recursive_stringify_keys! ⇒ Object
Recursive version of Rails' stringify_keys!.
Instance Method Details
#recursive_merge!(with_hash) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/omniconf/helpers.rb', line 11 def recursive_merge! with_hash self.merge!(with_hash) do |key, old_val, new_val| if new_val.is_a?(Hash) and old_val.is_a?(Hash) # merge sub-hashes together new_val = old_val.recursive_merge! new_val else # yield block when overriding yield key, old_val, new_val if block_given? and new_val != old_val end new_val end end |
#recursive_stringify_keys! ⇒ Object
Recursive version of Rails' stringify_keys!
3 4 5 6 7 8 9 |
# File 'lib/omniconf/helpers.rb', line 3 def recursive_stringify_keys! self.keys.each do |key| self[key.to_s] = self.delete(key) unless key.is_a? String self[key.to_s].recursive_stringify_keys! if self[key.to_s].is_a? Hash end self end |