Is there some kind of invisible Array interrupt in Ruby?

I am writing a method that takes variable lengths of arrays and compresses them and converts them to the corresponding lengths of the array.

The method takes an array length from 50 to 126 ... and converts them depending on the parameters when called. This means that I am dynamically accessing the ranges specified by the method call. It also means that I am accessing array indices that will not exist. In addition to this, the range I am referring to may be equal. Here is my problem: it seems that the final pocket of the array behaves strangely when accessing it with a range, unlike any other non-existent index

>> a = [0, 1, 2, 3, 4]
# => [0, 1, 2, 3, 4]  

>> a[5]
# => nil  

>> a[4..4]
# => [4]

>> a[6..6]
# => nil  

>> a[5..5]
# => [] <------GGRAAAAAhhh!!! Thought you were nil

>> a[5..7]
# => []   <-------you too

>> a[6..7]
# => nil <-----but you are behaving

- , ? , , rails. FWIW Ruby 1.8.6 Mac OS X, patchlevel 114

+4
3

Ruby Arrays. , .

:

a = [1,2,3]
a[3..3] = [4,5] # a = [1,2,3,4,5]

a >

EDIT: . .

0

All Articles