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
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
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
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
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!
-RFrom 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs