Project

General

Profile

Feature #20894

Updated by kyanagi (Kouhei Yanagita) 5 days ago

`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

Back