* [ruby-core:121252] [Ruby master Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError
@ 2025-03-06 20:31 andrykonchin (Andrew Konchin) via ruby-core
2025-03-07 10:28 ` [ruby-core:121256] " nobu (Nobuyoshi Nakada) via ruby-core
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: andrykonchin (Andrew Konchin) via ruby-core @ 2025-03-06 20:31 UTC (permalink / raw)
To: ruby-core; +Cc: andrykonchin (Andrew Konchin)
Issue #21174 has been reported by andrykonchin (Andrew Konchin).
----------------------------------------
Bug #21174: Range#max called with an argument on a beginless Integer Range raises RangeError
https://bugs.ruby-lang.org/issues/21174
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* ruby -v: 3.4.2
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
It seems surprising but instead of returning last `n` Integers `Range#max(n)` raises `RangeError`:
```ruby
(nil..10).max(2)
# => (irb):3:in 'Range#max': cannot get the maximum of beginless range with custom comparison method (RangeError)
```
I would expect `[9, 10]` to be returned.
--
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/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread* [ruby-core:121256] [Ruby master Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError
2025-03-06 20:31 [ruby-core:121252] [Ruby master Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError andrykonchin (Andrew Konchin) via ruby-core
@ 2025-03-07 10:28 ` nobu (Nobuyoshi Nakada) via ruby-core
2025-12-15 10:40 ` [ruby-core:124205] [Ruby " mame (Yusuke Endoh) via ruby-core
2025-12-17 9:32 ` [ruby-core:124281] " mame (Yusuke Endoh) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2025-03-07 10:28 UTC (permalink / raw)
To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)
Issue #21174 has been updated by nobu (Nobuyoshi Nakada).
andrykonchin (Andrew Konchin) wrote:
> I would expect `[9, 10]` to be returned.
`Range#max` returns the elements in greater order.
I think it should be `[10, 9]`, and `(..10).last(2)` should return `[9, 10]` without an exception too.
https://github.com/ruby/ruby/pull/12879
----------------------------------------
Bug #21174: Range#max called with an argument on a beginless Integer Range raises RangeError
https://bugs.ruby-lang.org/issues/21174#change-112209
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* ruby -v: 3.4.2
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
It seems surprising but instead of returning last `n` Integers `Range#max(n)` raises `RangeError`:
```ruby
(nil..10).max(2)
# => (irb):3:in 'Range#max': cannot get the maximum of beginless range with custom comparison method (RangeError)
```
I would expect `[9, 10]` to be returned.
--
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/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:124205] [Ruby Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError
2025-03-06 20:31 [ruby-core:121252] [Ruby master Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError andrykonchin (Andrew Konchin) via ruby-core
2025-03-07 10:28 ` [ruby-core:121256] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2025-12-15 10:40 ` mame (Yusuke Endoh) via ruby-core
2025-12-17 9:32 ` [ruby-core:124281] " mame (Yusuke Endoh) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2025-12-15 10:40 UTC (permalink / raw)
To: ruby-core; +Cc: mame (Yusuke Endoh)
Issue #21174 has been updated by mame (Yusuke Endoh).
It's a bit late to mention this, but I find this new behavior quite strange.
Range is used to represent both discrete sequences and continuous ranges, and when performing iterative operations, the begin value distinguishes between them.
Actually, while `(1..10).max(2)` returns `[9, 10]`, `(1.0..10).max(2)` raises an exception.
For beginless ranges, we can't tell it is discrete or continuous, so I think raising an exception is a good choice.
----------------------------------------
Bug #21174: Range#max called with an argument on a beginless Integer Range raises RangeError
https://bugs.ruby-lang.org/issues/21174#change-115680
* Author: andrykonchin (Andrew Konchin)
* Status: Closed
* ruby -v: 3.4.2
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
It seems surprising but instead of returning last `n` Integers `Range#max(n)` raises `RangeError`:
```ruby
(nil..10).max(2)
# => (irb):3:in 'Range#max': cannot get the maximum of beginless range with custom comparison method (RangeError)
```
I would expect `[9, 10]` to be returned.
--
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/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:124281] [Ruby Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError
2025-03-06 20:31 [ruby-core:121252] [Ruby master Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError andrykonchin (Andrew Konchin) via ruby-core
2025-03-07 10:28 ` [ruby-core:121256] " nobu (Nobuyoshi Nakada) via ruby-core
2025-12-15 10:40 ` [ruby-core:124205] [Ruby " mame (Yusuke Endoh) via ruby-core
@ 2025-12-17 9:32 ` mame (Yusuke Endoh) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2025-12-17 9:32 UTC (permalink / raw)
To: ruby-core; +Cc: mame (Yusuke Endoh)
Issue #21174 has been updated by mame (Yusuke Endoh).
I confirmed @matz and he said that the current behavior is OK. He prioritizes practicality over consistency in this case.
----------------------------------------
Bug #21174: Range#max called with an argument on a beginless Integer Range raises RangeError
https://bugs.ruby-lang.org/issues/21174#change-115778
* Author: andrykonchin (Andrew Konchin)
* Status: Closed
* ruby -v: 3.4.2
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
It seems surprising but instead of returning last `n` Integers `Range#max(n)` raises `RangeError`:
```ruby
(nil..10).max(2)
# => (irb):3:in 'Range#max': cannot get the maximum of beginless range with custom comparison method (RangeError)
```
I would expect `[9, 10]` to be returned.
--
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/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-17 9:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-06 20:31 [ruby-core:121252] [Ruby master Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError andrykonchin (Andrew Konchin) via ruby-core
2025-03-07 10:28 ` [ruby-core:121256] " nobu (Nobuyoshi Nakada) via ruby-core
2025-12-15 10:40 ` [ruby-core:124205] [Ruby " mame (Yusuke Endoh) via ruby-core
2025-12-17 9:32 ` [ruby-core:124281] " mame (Yusuke Endoh) via ruby-core
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 NNTP newsgroup(s).