Module: DeepMergeable
- Included in:
- Hash
- Defined in:
- lib/extensions/hash/deep_mergeable.rb
Instance Method Summary collapse
- #deep_merge(other) ⇒ Object
-
#deep_merge!(other, &block) ⇒ Object
Same as #deep_merge, but modifies
self. - #deep_merge?(other) ⇒ Boolean
Instance Method Details
#deep_merge(other) ⇒ Object
4 5 6 |
# File 'lib/extensions/hash/deep_mergeable.rb', line 4 def deep_merge(other, &) dup.deep_merge!(other, &) end |
#deep_merge!(other, &block) ⇒ Object
Same as #deep_merge, but modifies self.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/extensions/hash/deep_mergeable.rb', line 9 def deep_merge!(other, &block) merge!(other) do |key, this_val, other_val| if this_val.is_a?(DeepMergeable) && this_val.deep_merge?(other_val) this_val.deep_merge(other_val, &block) elsif block_given? yield(key, this_val, other_val) else other_val end end end |
#deep_merge?(other) ⇒ Boolean
21 22 23 |
# File 'lib/extensions/hash/deep_mergeable.rb', line 21 def deep_merge?(other) other.is_a?(self.class) end |