Issue #15747 has been updated by wanabe (_ wanabe).

Backport deleted (2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN)
ruby -v deleted (ruby 2.7.0dev (2019-04-04 trunk 67430) [x86_64-linux])
Tracker changed from Bug to Feature

Thank you to response.


mame (Yusuke Endoh) wrote:
> In general, I think that an enumerating operation against a beginless range should raise an exception.  It is also the case at `Range#last` with an argument.  Note that the meaning of `Range#last` with no argument is fairly different from the version with a length argument.  See #8739 and #15523.

Oh, I've missed #8739 and #15523. Thank you.

> That said, `Range#last` might be handled as a special case.  I have no strong opinion about this, but an exception is still one of the most reasonable design choices.
> 
> 1) It is difficult to reversely enumerate the elements of Range from last.  AFAIK, there is no precedent.
> 
> 2) `(-Float::INFINITY .. 1).last(2)` also raises a TypeError.
> 
> ```
> (-Float::INFINITY .. 1).last(2) #=> can't iterate from Float (TypeError)
> ```

OK. I have no strong opinion, too.
I have realized this is a not "Bug". I change the tracker "Feature".

----------------------------------------
Feature #15747: `(..1).last(2)` should return array but raise TypeError
https://bugs.ruby-lang.org/issues/15747#change-77465

* Author: wanabe (_ wanabe)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
`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
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>