Project

General

Profile

Actions

Bug #4245

closed

Array index with Range inconsistency

Added by kristianpd (Kristian PD) almost 14 years ago. Updated over 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
1.8.7
Backport:
[ruby-core:34189]

Description

=begin
I've come across what I believe to be a possible inconsistency in the implementation of the Range array index method. The following example describes my case:

array = [1,2,3,4,5]

tests
a) array[0..5] // [1,2,3,4,5]
b) array[4..-1] // [5]
c) array[5..-1] // []
d) array[6..-1] // nil

additional tests
e) array[5..10] // []
f) array[6..10] // nil

I would have expected cases c and d to both return nil according to the docs: "Returns nil if the index (or starting index) are out of range."

Out of curiosity I also added tests e and f to make sure it was not related to the end of the range being -1.

Without having had a chance to check the code, my instinct here is that a comparison is possibly being done on the .count/.length of the array when building the result and comparing that to the first part of the range sequence.

Am I missing another reason for this?

Kristian
=end


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Feature #4541: Inconsistent Array.slice()Rejectedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0