-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deep_merge overwriting works differently than Hash#merge #16
Comments
It looks like there are other inconstancies around
|
@jpb -- I'm the original author of this gem, fyi - I've been away from the coding world for a little while :) Regarding your first point, it is intentional for deep_merge to deviate from merge. While it's unfortunate in terms of mnemonics / syntax consistency, it's (IMO) preferable b/c we can offer both types of functionality. So you can write this to make it compatible with merge:
The inconsistencies in your second example are intentional also. Arguably unhelpful for some use-cases for sure, but the purpose of this gem was originally to merge options coming in from an HTTP request (checkboxes and other filter parameters). A nil option doesn't overwrite existing elements. But if you convert your nil to a "knockout" parameter, you can use it to zero out the existing parameter (different than replacing it with a nil, which may not be a supported operation in the current system). But it gets you closer. It would be possible to fairly easily modify the code to replace an existing with nil, on presence of the knockout parameter. (If you want tips on how to do that let me know). But it's probably harder to change the default behavior of how nils are handled without breaking a bunch of tests (and other people's code dependencies).
Apologies that this library is non-standard in this way. It was originally tailored for a very specific use case and subsequently generalized without consideration for aligning to how Hash.merge works. |
😱 |
deep_merge
behaves different thanHash#merge
, whereHash#merge
overwrites a key's value of the original hash if the hash being merged in contains the same key. The opposite is true fordeep_merge
.Is this as intended, or is this a bug in
deep_merge
?The text was updated successfully, but these errors were encountered: