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
···
--
Posted via http://www.ruby-forum.com/.
fedzor
(fedzor)
2
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
···
On Jul 15, 2008, at 1:13 AM, Roger Pack wrote:
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?
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 Gutteridge
Department of Biochemistry
University of Cambridge
···
On 15 Jul 2008, at 06:13, Roger Pack wrote:
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
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
···
On 15 Jul 2008, at 15:07, Alex Gutteridge wrote:
On 15 Jul 2008, at 06:13, Roger Pack wrote:
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
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...