Project

General

Profile

Actions

Bug #11501

closed

About priority of a hash element when using {**hash1, **hash2} literal

Added by studio3104 (Satoshi SUZUKI) about 9 years ago. Updated almost 9 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
[ruby-dev:<unknown>]

Description

When creating a new hash using { **hash1, **hash2 } literal,
there are different behaviors between 2.2.0 or later and 2.1.7 or earlier like below.

  • ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13]
  • ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
[1] pry(main)> hash1 = { duplicate_key: 1, key: 1 }
=> {:duplicate_key=>1, :key=>1}
[2] pry(main)> hash2 = { duplicate_key: 3 }
=> {:duplicate_key=>3}
[3] pry(main)> { **hash1, **hash2 }
=> {:duplicate_key=>3, :key=>1}
[4] pry(main)>
  • ruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-darwin13.0]
[1] pry(main)> hash1 = { duplicate_key: 1, key: 1 }
=> {:duplicate_key=>1, :key=>1}
[2] pry(main)> hash2 = { duplicate_key: 3 }
=> {:duplicate_key=>3}
[3] pry(main)> { **hash1, **hash2 }
=> {:duplicate_key=>1, :key=>1}
[4] pry(main)>

It seems that the behavior has changed from 2.2.0, however there is no mention in any documents as far as I searched.

Is this intended change?
Please check this and give me a opinion.
Warm Regards.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #10315: Override policy for duplicated keywordsClosedmatz (Yukihiro Matsumoto)10/02/2014Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0