method
deep_merge
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes -
Class: DeepMergeable
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
deep_merge(other, &block)
public
Returns a new instance with the values from other merged recursively.
class Hash include ActiveSupport::DeepMergeable end hash_1 = { a: true, b: { c: [1, 2, 3] } } hash_2 = { a: false, b: { x: [3, 4, 5] } } hash_1.deep_merge(hash_2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
A block can be provided to merge non-DeepMergeable values:
hash_1 = { a: 100, b: 200, c: { c1: 100 } } hash_2 = { b: 250, c: { c1: 200 } } hash_1.deep_merge(hash_2) do |key, this_val, other_val| this_val + other_val end # => { a: 100, b: 450, c: { c1: 300 } }