Project

General

Profile

Actions

Bug #21174

closed

Range#max called with an argument on a beginless Integer Range raises RangeError

Added by andrykonchin (Andrew Konchin) 6 days ago. Updated 5 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:121252]

Description

It seems surprising but instead of returning last n Integers Range#max(n) raises RangeError:

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

Updated by nobu (Nobuyoshi Nakada) 5 days ago

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

Actions #2

Updated by nobu (Nobuyoshi Nakada) 5 days ago

  • Status changed from Open to Closed

Applied in changeset git|cbe3156f82ee8b68e734be58badb9b6a3adc8aa6.


[Bug #21174] [Bug #21175] Fix Range#max on beginless integer range

Actions

Also available in: Atom PDF

Like0
Like1Like0