Project

General

Profile

Actions

Bug #21921

open

Hash inconsistent ==, >=, <= behavior

Bug #21921: Hash inconsistent ==, >=, <= behavior

Added by cohen (Cohen Carlisle) 1 day ago. Updated about 22 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux]
[ruby-core:124857]

Description

Hash seems to have very inconsistent behavior for ==, >=, and <=.
Given that below h1 == h2 is false and that they have the same number of keys, I would expect <= and >= to also be false.
However, surprisingly h1 <= h2 and h2 >= h1 are true, while all other permutations are false.

h1 = {}.compare_by_identity.tap { _1["one"] = 1 } # => {"one" => 1}
h2 = {"one" => 1} # => {"one" => 1}
h1 == h2 # => false
h2 == h1 # => false
h1 >= h2 # => false
h1 <= h2 # => true
h2 >= h1 # => true
h2 <= h1 # => false
Actions

Also available in: PDF Atom