[#70843] Re: [ruby-cvs:58952] hsbt:r51801 (trunk): * lib/rubygems: Update to RubyGems HEAD(fe61e4c112). — Eric Wong <normalperson@...>
hsbt@ruby-lang.org wrote:
3 messages
2015/09/17
[ruby-core:70666] [Ruby trunk - Bug #11508] Hash#eql? does not respect hash ordering
From:
nobu@...
Date:
2015-09-04 23:30:31 UTC
List:
ruby-core #70666
Issue #11508 has been updated by Nobuyoshi Nakada.
New ticket for a new method, please.
----------------------------------------
Bug #11508: Hash#eql? does not respect hash ordering
https://bugs.ruby-lang.org/issues/11508#change-54060
* Author: Eike Dierks
* Status: Closed
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
~~~ruby
{a:1,b:2}.eql?({b:2,a:1})
=> true
~~~
The `eql?` (aka `==`) operator on hashes does not compare the ordering of the compared hashes.
This behaviour is documented in `Hash#==` (and should not be touched, ever)
I'd like to suggest:
- extend the documentation of `Hash#==` to *explicitely* state, that ordering is not compared
- add a new function in ruby5 to compare hashes with respect of the ordering,
aka `{a:1,b:2}.eql_with_order?({b:2,a:1})` => `false`
--
https://bugs.ruby-lang.org/