Project

General

Profile

Actions

Bug #18953

closed

`Array#uniq` doesn't evaluate the given block when the size of the array is one

Added by ttanimichi (Tsukuru Tanimichi) over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
[ruby-dev:51189]

Description

Array#uniq doesn't evaluate the given block when the size of the array is one. Is this expected behavior?

$ ruby -e '[42, 43].uniq { _1.foo }; puts true'
-e:1:in `block in <main>': undefined method `foo' for 42:Integer (NoMethodError)

[42, 43].uniq { _1.foo }; puts true
                  ^^^^
Did you mean?  floor
	from -e:1:in `uniq'
	from -e:1:in `<main>'
$ ruby -e '[42].uniq { _1.foo }; puts true'
true
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0