danielsdeleo / deep_merge

Recursive Merging for Ruby Hashes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple nested usecase not working

ankilosaurus opened this issue · comments

{a: {b: 1}}.deep_merge(a: {b: 2}) returns {:a=>{:b=>1}}

... using https://github.com/mcrossen/deepsort now which behaves as expected

This is a safety feature to not "overwrite unmergeables" by default. You should call the destructive form deep_merge! to get what you want:

{a: {b: 1}}.deep_merge!(a: {b: 2})
=> {:a=>{:b=>1}}
{a: {b: 1}}.deep_merge!(a: {b: 2})
=> {:a=>{:b=>2}}

The idea is that if an interior object cannot actually merged (like an array) then it shouldn't be overwritten unless the ! operator is used.

I understand the reasoning, but some sort of warning might be nice so people don't assume it's working (I spent a while debugging this issue myself).
Personally I can't think of any use case where you want that to happen silently (happy to be corrected on this).

This is documented in the README, so I'm closing this one.