ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:51189] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one
@ 2022-08-02  2:15 ttanimichi (Tsukuru Tanimichi)
  2022-08-03  4:52 ` [ruby-dev:51190] " mrkn (Kenta Murata)
  2022-08-03  6:12 ` [ruby-dev:51191] " nobu (Nobuyoshi Nakada)
  0 siblings, 2 replies; 3+ messages in thread
From: ttanimichi (Tsukuru Tanimichi) @ 2022-08-02  2:15 UTC (permalink / raw
  To: ruby-dev

Issue #18953 has been reported by ttanimichi (Tsukuru Tanimichi).

----------------------------------------
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

* 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:51190] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one
  2022-08-02  2:15 [ruby-dev:51189] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one ttanimichi (Tsukuru Tanimichi)
@ 2022-08-03  4:52 ` mrkn (Kenta Murata)
  2022-08-03  6:12 ` [ruby-dev:51191] " nobu (Nobuyoshi Nakada)
  1 sibling, 0 replies; 3+ messages in thread
From: mrkn (Kenta Murata) @ 2022-08-03  4:52 UTC (permalink / raw
  To: ruby-dev

Issue #18953 has been updated by mrkn (Kenta Murata).


I hope this behavior should be expected.
However, `sort_by`, `max_by`, and `min_by` call the given blocks even if the receiver array has only one item.

```
irb(main):001:0> [42].sort_by { _1.foo }
(irb):1:in `block in <top (required)>': undefined method `foo' for 42:Integer (NoMethodError)
Did you mean?  floor
	from (irb):1:in `each'
	from (irb):1:in `sort_by'
	from (irb):1:in `<main>'
	from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load'
	from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `<main>'
irb(main):002:0> [42].max_by { _1.foo }
(irb):2:in `block in <top (required)>': undefined method `foo' for 42:Integer (NoMethodError)
Did you mean?  floor
	from (irb):2:in `each'
	from (irb):2:in `max_by'
	from (irb):2:in `<main>'
	from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load'
	from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `<main>'
irb(main):003:0> [42].min_by { _1.foo }
(irb):3:in `block in <top (required)>': undefined method `foo' for 42:Integer (NoMethodError)
Did you mean?  floor
	from (irb):3:in `each'
	from (irb):3:in `min_by'
	from (irb):3:in `<main>'
	from /home/mrkn/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'
	from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `load'
	from /home/mrkn/.rbenv/versions/3.1.0/bin/irb:25:in `<main>'
```

----------------------------------------
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-98570

* 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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:51191] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one
  2022-08-02  2:15 [ruby-dev:51189] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one ttanimichi (Tsukuru Tanimichi)
  2022-08-03  4:52 ` [ruby-dev:51190] " mrkn (Kenta Murata)
@ 2022-08-03  6:12 ` nobu (Nobuyoshi Nakada)
  1 sibling, 0 replies; 3+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2022-08-03  6:12 UTC (permalink / raw
  To: ruby-dev

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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-03  6:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-02  2:15 [ruby-dev:51189] [Ruby master Bug#18953] `Array#uniq` doesn't evaluate the given block when the size of the array is one ttanimichi (Tsukuru Tanimichi)
2022-08-03  4:52 ` [ruby-dev:51190] " mrkn (Kenta Murata)
2022-08-03  6:12 ` [ruby-dev:51191] " nobu (Nobuyoshi Nakada)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).