[ruby-dev:51191] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one

From: "nobu (Nobuyoshi Nakada)" <noreply@...>
Date: 2022-08-03 06:12:49 UTC
List: ruby-dev #51191
Issue #18953 has been updated by nobu (Nobuyoshi Nakada).


I think this is an expected behavior, but an implementation detail.

----------------------------------------
Bug #18953: `Array#uniq` doesn't evaluate the given block when the size of the array is one
https://bugs.ruby-lang.org/issues/18953#change-98571

* Author: ttanimichi (Tsukuru Tanimichi)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`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
```




-- 
https://bugs.ruby-lang.org/

In This Thread

Prev Next