Class: Radar::Support::Hash
- Inherits:
-
Object
- Object
- Radar::Support::Hash
- Defined in:
- lib/radar/support.rb
Overview
Hash support methods:
- #deep_merge and #deep_merge! - Does what it says: deep merges a hash with another hash. Taken from ActiveSupport in Rails 3.
Class Method Summary collapse
-
.deep_merge(source, other) ⇒ Object
Returns a new hash with +self+ and +other_hash+ merged recursively.
-
.deep_merge!(source, other) ⇒ Object
Returns a new hash with +self+ and +other_hash+ merged recursively.
Class Method Details
.deep_merge(source, other) ⇒ Object
Returns a new hash with +self+ and +other_hash+ merged recursively.
10 11 12 |
# File 'lib/radar/support.rb', line 10 def self.deep_merge(source, other) deep_merge!(source.dup, other) end |
.deep_merge!(source, other) ⇒ Object
Returns a new hash with +self+ and +other_hash+ merged recursively. Modifies the receiver in place.
16 17 18 19 20 21 22 23 |
# File 'lib/radar/support.rb', line 16 def self.deep_merge!(source, other) other.each_pair do |k,v| tv = source[k] source[k] = tv.is_a?(::Hash) && v.is_a?(::Hash) ? deep_merge(tv, v) : v end source end |