Actions
Feature #18986
openRaises Exception for Range#last(n) with Float::INFINITY
Status:
Open
Assignee:
-
Target version:
-
Description
When a (Numeric) argument is given to Range#last(n)
for a Range with Float::INFINITY
, it runs into an infinite loop (see a small code snippet below).
There is no use case for the feature as far as I can think of, and it is hard to detect.
(6..Float::INFINITY).last(1) # => infinite loop!!
(6..).last(1) # cannot get the last element of endless range (RangeError)
(-Float::INFINITY..4).last(1) # can't iterate from Float (TypeError)
(..4).last(1) # can't iterate from Float (TypeError)
Let me suggest raising an Exception (maybe RangeError, in the same way as an endless Range) when last(n)
is specified for a Range whose end value is Float::INFINITY
.
I note (6..Float::INFINITY).to_a
has the same issue.
No data to display
Actions
Like0