Project

General

Profile

Bug #10023

Hash#merge fails duplicating objects

Added by coyote (Alexey Babich) almost 5 years ago. Updated almost 5 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.1.2
[ruby-core:63629]

Description

Here is an example in IRB (ruby 2.1.2):

A={b:{}}
=> {:b=>{}}
c=A.merge({c: {d: 'e'}})
=> {:b=>{}, :c=>{:d=>"e"}}
c[:b][:d] = "f"
=> "f"
A
=> {:b=>{:d=>"f"}}

Every key, value pair is expected to be duplicated during the merge? Please, investigate if this is a bug

History

Updated by coyote (Alexey Babich) almost 5 years ago

Please, also note that Rails' deep_merge does not help

Updated by coyote (Alexey Babich) almost 5 years ago

The same with duplication

c=A.dup #same .clone
=> {:b=>{}}
c.merge!({c: {d: 'e'}})
=> {:b=>{}, :c=>{:d=>"e"}}
c[:b][:d] = 'bug'
=> "bug"
A
=> {:b=>{:d=>"bug"}}

Updated by coyote (Alexey Babich) almost 5 years ago

Please, note that only Rails' deep_dup seems helpful to workaround the issue

Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

  • Status changed from Open to Rejected

Not a bug.
A[:b] and c[:b] refer the same object.
Check its object_id.

Also available in: Atom PDF