From: "tycooon (Yuri Smirnov) via ruby-core" Date: 2023-04-28T12:08:18+00:00 Subject: [ruby-core:113376] [Ruby master Bug#19622] Undocumented behavior of Array#& and similar methods Issue #19622 has been reported by tycooon (Yuri Smirnov). ---------------------------------------- Bug #19622: Undocumented behavior of Array#& and similar methods https://bugs.ruby-lang.org/issues/19622 * Author: tycooon (Yuri Smirnov) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- Currently, the docs only state that the objects are compared using `eql?` method. However, it turns out that if arrays are "big" (size more than `SMALL_ARRAY_LEN`), then the hash is used so things stop working unless you also redefine `hash` method. I know that there is information regarding that in the `eql?` method docs (see https://ruby-doc.org/3.2.2/Object.html#method-i-eql-3F), however it's very likely that people will just go ahead and define the `eql?` method and everything will work until some point in time. So I think it would be great to update the docs for Array method `&`, `intersection` and `intersect?` to clearly state that both `eql?` and `hash` methods are used. -- 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/postorius/lists/ruby-core.ml.ruby-lang.org/