Project

General

Profile

Feature #15747

`(..1).last(2)` should return array but raise TypeError

Added by wanabe (_ wanabe) about 1 year ago. Updated 8 months ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:92138]

Description

Range#last with argument for beginless range shouldn't raise exception, should it?

$ ./miniruby -ve 'p (..1).last(2)'
ruby 2.7.0dev (2019-04-04 trunk 67430) [x86_64-linux]
Traceback (most recent call last):
    4: from -e:1:in `<main>'
    3: from -e:1:in `last'
    2: from -e:1:in `to_a'
    1: from -e:1:in `to_a'
-e:1:in `each': can't iterate from NilClass (TypeError)

Range#last without argument works fine.

$ ./miniruby -ve 'p (..1).last'
ruby 2.7.0dev (2019-04-04 trunk 67430) [x86_64-linux]
1

Also available in: Atom PDF