Project

General

Profile

Actions

Bug #19622

closed

Undocumented behavior of Array#& and similar methods

Added by tycooon (Yuri Smirnov) about 1 year ago. Updated 12 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
[ruby-core:113376]

Description

Currently, the Array#& 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 methods &, intersection and intersect? to clearly state that both eql? and hash methods are used.

Actions #1

Updated by tycooon (Yuri Smirnov) about 1 year ago

  • Description updated (diff)
Actions #2

Updated by tycooon (Yuri Smirnov) about 1 year ago

  • Description updated (diff)
Actions #3

Updated by tycooon (Yuri Smirnov) about 1 year ago

  • Description updated (diff)
Actions #4

Updated by jeremyevans (Jeremy Evans) 12 months ago

  • Status changed from Open to Closed

Applied in changeset git|986268afae7bde07073da3ba483d12549b12801f.


Document that Array#{&,intersection,intersect?} use hash method [ci skip]

Fixes [Bug #19622]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0