You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -38,6 +40,8 @@ Introduction to core features of the [Ruby](https://www.ruby-lang.org) programmi
38
40
-[Map Methods](#map-methods)
39
41
-[Inject Methods](#inject-methods)
40
42
-[Sort Methods](#sort-methods)
43
+
-[Merge Methods](#merge-methods)
44
+
</details>
41
45
42
46
# Getting Started
43
47
@@ -1409,4 +1413,40 @@ end
1409
1413
hash.sort do |pair_1, pair_2|
1410
1414
pair_1[1] <=> pair_2[1]
1411
1415
end
1412
-
```
1416
+
```
1417
+
1418
+
## Merge Methods
1419
+
1420
+
Merge methods only apply to hashes and are able to merge two of them together. Takes the keys and values of one `hash` and from another to form a new `hash`. A block can be provided to it in order to provide rules when performing that merge.
In the example above, two hashes were merged. There were no conflicts except with the value of `hash_1[:a]` and `hash_2[:a]` as those were different.
1431
+
1432
+
The merge method chose to get the value of the hash being merged in by default but this can be overridden with a code block. Ruby will make use of the code block in the case of a key conflict.
0 commit comments