-
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
Inconsistent behaviour between bang and no-bang method #56
Comments
i faced with expected behavior irb(main):013:0> hash1 = { a: 1, b: 2 }
irb(main):014:0> hash2 = { a: 3, c: 4 }
irb(main):015:0> puts hash1
{:a=>1, :b=>2}
=> nil
irb(main):016:0> puts hash2
{:a=>3, :c=>4}
=> nil
irb(main):017:0> hash1.deep_merge(hash2)
=> {:a=>3, :b=>2, :c=>4}
irb(main):018:0> hash1.deep_merge!(hash2)
=> {:a=>3, :b=>2, :c=>4}
irb(main):019:0> hash1 = { a: 1, b: 2 }
irb(main):020:0> hash2 = { a: 3, c: 4 }
irb(main):021:0> hash1.deep_merge!(hash2)
=> {:a=>3, :b=>2, :c=>4}
irb(main):022:0> puts hash1
{:a=>3, :b=>2, :c=>4}
=> nil
irb(main):023:0> hash1 = { a: 1, b: 2 }
irb(main):024:0> hash2 = { a: 3, c: 4 }
irb(main):025:0> hash1.deep_merge(hash2)
=> {:a=>3, :b=>2, :c=>4}
irb(main):026:0> puts hash1
{:a=>1, :b=>2}
=> nil
irb(main):027:0> |
I'm still seeing my reported behaviour:
Edit: Actually, I think what I'm observing is #26. The non-bang method destructively modifies
Edit 2: But that doesn't explain the inconsistent behaviour:
|
it modifies by design, which is confusing ... fix to remove it #59 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This difference in behaviour seems counterintuitive. Usually the bang method is the destructive equivalent of the non-bang method returning the same result.
I want the behaviour of
deep_merge!
above where:a
's value is overwritten but I don't want to apply it destructively to the originalhash1
object. Can this be done?The text was updated successfully, but these errors were encountered: