Actions
Feature #20894
openAllow `Range#last(n)` for beginless ranges with Integer end
Status:
Open
Assignee:
-
Target version:
-
Description
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.
Updated by kyanagi (Kouhei Yanagita) about 1 month ago
- Description updated (diff)
Actions
Like0
Like0