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

From: ruby-core@...
Date: 2016-01-11 01:02:25 UTC
List: ruby-core #72802
Issue #11975 has been updated by Marc-Andre Lafortune.

Status changed from Open to Rejected

This is intentional and documented:

"Note that with no arguments +last+ will return the object that defines the end of the range even if #exclude_end? is +true+."

Changing that would create incompatibilities that would far outweigh any benefit (if any).

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

* 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