# Array ending syntax question

**URL:** <https://www.ruby-forum.com/t/array-ending-syntax-question/143098>\
**Category:** Ruby\
**Created:** [July 15, 2008, 7:17am UTC](https://www.ruby-forum.com/t/array-ending-syntax-question/143098 "2008-07-15T07:17:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [July 15, 2008, 7:17am UTC](https://www.ruby-forum.com/t/array-ending-syntax-question/143098/1 "2008-07-15T07:17:48Z")

</div>

irb(main):001:0\> [1,2][2…2]  
=\> []  
irb(main):002:0\> [1,2][3…3]  
=\> nil

Is this expected?  
the ri says:  
Returns nil if the index (or starting index) are out of range.

does the first example match this?  
Thanks!  
-R

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [July 15, 2008, 4:04pm UTC](https://www.ruby-forum.com/t/array-ending-syntax-question/143098/2 "2008-07-15T16:04:43Z")

</div>

On Jul 15, 2008, at 1:13 AM, Roger P. wrote:

> does the first example match this?  
> Yes, because array indices start at 0. So the highest index in the  
> example is 1.

-------------------------------------------------------|  
~ Ari  
Some people want love  
Others want money  
Me… Well…  
I just want this code to compile

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [July 15, 2008, 4:12pm UTC](https://www.ruby-forum.com/t/array-ending-syntax-question/143098/3 "2008-07-15T16:12:57Z")

</div>

On 15 Jul 2008, at 06:13, Roger P. wrote:

> does the first example match this?  
> Thanks!  
> -R

From the Pickaxe: If the start index equals the array size and a  
length or range (as here) parameter is given, an empty array is  
returned.

Not sure why you would want that behaviour though…

Alex G.

Department of Biochemistry  
University of Cambridge

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [July 15, 2008, 6:57pm UTC](https://www.ruby-forum.com/t/array-ending-syntax-question/143098/4 "2008-07-15T18:57:54Z")

</div>

On 15 Jul 2008, at 15:07, Alex G. wrote:

> > Returns nil if the index (or starting index) are out of range.
> > 
> > does the first example match this?  
> > Thanks!  
> > -R
> 
> From the Pickaxe: If the start index equals the array size and a  
> length or range (as here) parameter is given, an empty array is  
> returned.
> 
> Not sure why you would want that behaviour though…

It sort of makes sense in that in an n item array n is actually a  
useful index - it’s where the next item will go.

Fred
