From: "mame (Yusuke Endoh) via ruby-core" Date: 2025-12-15T10:40:07+00:00 Subject: [ruby-core:124205] [Ruby Bug#21174] Range#max called with an argument on a beginless Integer Range raises RangeError 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/