From: "mame (Yusuke Endoh) via ruby-core" Date: 2026-02-21T18:13:07+00:00 Subject: [ruby-core:124863] [Ruby Bug#21921] Hash inconsistent ==, >=, <= behavior Issue #21921 has been updated by mame (Yusuke Endoh). By the way, I noticed the following behavior, which feels like it might not satisfy the specification: ```ruby h1 = {}.compare_by_identity h1["one"] = true h1["one"] = true h2 = { "one" => true } h1 <= h2 # current: false, expected(?): true ``` The two `"one" => true` entries in `h1` can both be considered to be included in `h2`, so the spec seems to imply this should return `true`. However, I'm torn on whether we should explicitly describe such implementation details in the documentation. ---------------------------------------- Bug #21921: Hash inconsistent ==, >=, <= behavior https://bugs.ruby-lang.org/issues/21921#change-116517 * Author: cohen (Cohen Carlisle) * Status: Open * ruby -v: ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- 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 ``` -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/