Array index confusion

I cannot find an answer to this, and perhaps the answer is that "it is
what it is..." But perhaps someone can explain this for me.

If I have an array, thus:
   a = [1, 2, 3, 4]
there are four elements in the array. The indexes are 0..3.

a[4,0] returns []

a[5,0], however, returns nil

Both of these are outside the scope of the array, aren't they? I would
think they would return the same thing, either nil or the empty array.

Any help? Thanks!

John

···

--
Posted via http://www.ruby-forum.com/.

Maybe this helps:

<Array slicing in Ruby: explanation for illogical behaviour (taken from Rubykoans.com) - Stack Overflow;

Regards,
Marcus

···

Am 20.06.2012 23:27, schrieb John R.:

I cannot find an answer to this, and perhaps the answer is that "it is
what it is..." But perhaps someone can explain this for me.

If I have an array, thus:
    a = [1, 2, 3, 4]
there are four elements in the array. The indexes are 0..3.

a[4,0] returns

a[5,0], however, returns nil

Both of these are outside the scope of the array, aren't they? I would
think they would return the same thing, either nil or the empty array.

--
<https://github.com/stomar/&gt;
<http://www.rubygems.org/profiles/stomar/&gt;

See this post for an explanation: http://www.ruby-forum.com/topic/1393096#990065

-- Matma Rex

This behavior definitely should be documented in the Array class.

···

Am 20.06.2012 23:38, schrieb Bartosz Dziewoński:

See this post for an explanation: String/array slices - Ruby - Ruby-Forum

--
<https://github.com/stomar/&gt;
<http://www.rubygems.org/profiles/stomar/&gt;

It's always humbling when you realize other people have thought through complicated stuff before you.

Dave

···

On 06/20/2012 04:38 PM, Bartosz Dziewoński wrote:

See this post for an explanation: String/array slices - Ruby - Ruby-Forum

-- Matma Rex

Good idea. Here's how:

-Justin

···

On 06/20/2012 11:07 PM, sto.mar@web.de wrote:

Am 20.06.2012 23:38, schrieb Bartosz Dziewoński:

See this post for an explanation: http://www.ruby-forum.com/topic/1393096#990065

This behavior definitely should be documented in the Array class.

Is this obsolete:
<http://www.ruby-doc.org/documentation-guidelines.html&gt; ?

Regards,
Marcus

···

Am 22.06.2012 00:56, schrieb Justin Collins:

On 06/20/2012 11:07 PM, sto.mar@web.de wrote:

...

This behavior definitely should be documented in the Array class.

Good idea. Here's how:

Ruby Documentation Project

--
<https://github.com/stomar/&gt;
<http://www.rubygems.org/profiles/stomar/&gt;

That site looks more specific to ruby-doc.org (e.g., using "stdlib-doc" to generate docs, instead of rdoc). I don't know if following those instructions will work or not. The instructions in the link I sent will.

-Justin

···

On 06/21/2012 11:13 PM, sto.mar@web.de wrote:

Am 22.06.2012 00:56, schrieb Justin Collins:

On 06/20/2012 11:07 PM, sto.mar@web.de wrote:

...

This behavior definitely should be documented in the Array class.

Good idea. Here's how:

Ruby Documentation Project

Is this obsolete:
<http://www.ruby-doc.org/documentation-guidelines.html&gt; ?

Regards,
Marcus

A late update: I submitted a patch for the documentation,
see <https://bugs.ruby-lang.org/issues/6680>

···

--
<https://github.com/stomar/>