Project

General

Profile

Actions

Bug #11508

closed

Hash#eql? does not respect hash ordering

Added by eike.rb (Eike Dierks) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
[ruby-core:<unknown>]

Description

{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
Actions #1

Updated by eike.rb (Eike Dierks) over 8 years ago

ruby5 -> ruby3

maybe we should try it in rails support first.

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Description updated (diff)
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Status changed from Open to Closed

Applied in changeset r51763.


hash.c: [DOC] orders do not matter [ci skip]

  • hash.c (rb_hash_equal, rb_hash_eql): [DOC] the orders of each
    hashes are not compared. [Bug #11508]
Actions #4

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

New ticket for a new method, please.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0