-
Notifications
You must be signed in to change notification settings - Fork 21.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deep duplicate in
deep_merge
so no references remain to the origina…
…l hash in the result When deep merging a Hash, first a duplicate is created. The duplicate only does a shallow copy, so deeper level structures are not duplicated but remain references. This can lead to unexpected modifications of the original hash when a deeply nested hash is merged with another hash, and the newly returned hash gets modified. ``` x = { a: { b: "foo" } } y = { d: { e: "bar" } } z = x.deep_merge(y) # z => { a: { b: "foo" }, d: { e: "bar" } } z[:a][:b] = "baz" # z => { a: { b: "baz" }, d: { e: "bar" } } # x => { a: { b: "baz" } } ```
- Loading branch information
1 parent
3b1fae4
commit 71ab41a
Showing
3 changed files
with
15 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters