[ruby-core:72803] [Ruby trunk - Bug #11975] Range#last is not consistent and possibly does not do what is expected.

From: nobu@...
Date: 2016-01-11 02:33:58 UTC
List: ruby-core #72803
Issue #11975 has been updated by Nobuyoshi Nakada.


Range is not only for discrete values.
What will you expect for `(0.0...1.0).last`?

----------------------------------------
Bug #11975: Range#last is not consistent and possibly does not do what is expected.
https://bugs.ruby-lang.org/issues/11975#change-56047

* Author: Samuel Williams
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: 2.3.0
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
The following example demonstrates an inconsistency with Range:

This is expected behaviour:

~~~
(0..10).last => 10
(0..10).to_a.last => 10
~~~

This is unexpected behaviour:

~~~
(0...10).last => 10 # (should be 9?)
(0...10).to_a.last => 9
~~~

I believe that Range#last should give the last valid value for a range. Discussion?



-- 
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>

In This Thread

Prev Next