[ruby-core:119929] [Ruby master Feature#20894] Allow `Range#last(n)` for beginless ranges with Integer end

Issue #20894 has been reported by kyanagi (Kouhei Yanagita). ---------------------------------------- Feature #20894: Allow `Range#last(n)` for beginless ranges with Integer end https://bugs.ruby-lang.org/issues/20894 * Author: kyanagi (Kouhei Yanagita) * Status: Open ---------------------------------------- `Range#last(n)` raises an exception on beginless ranges. ``` (..5).last(3) #=> can't iterate from NilClass (TypeError) ``` Since Ruby 3.3, `Range#reverse_each` for beginless ranges with an integer end has been allowed. ``` (..5).reverse_each { p _1 } #=> 5, 4, 3, 2, 1, ... ``` Therefore, shouldn't `Range#last(n)` for such ranges also be acceptable? ``` # before (..5).last(3) => can't iterate from NilClass (TypeError) # after (..5).last(3) => [3, 4, 5] ``` If this is accepted, a similar change could be considered for `Range#max(n)` as well. https://github.com/ruby/ruby/pull/12084 -- https://bugs.ruby-lang.org/
participants (1)
-
kyanagi (Kouhei Yanagita)