Actions
Bug #18688
closedwhen array's default value is empty hash adding a hash key value changes all array elements
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
Description
ah = Array.new(3, {})
ah[1][:foo] = 'bar'
p ah # [{:foo=>"bar"}, {:foo=>"bar"}, {:foo=>"bar"}]
This is not expected result. The expected result is [{}, {:foo=>"bar"}, {}]
.
Alternatively, below code works as expected.
ah = Array.new(3) {{}}
ah[1][:foo] = 'bar'
p ah # [{}, {:foo=>"bar"}, {}]
Actions
Like0
Like0