Issue #6680 has been updated by stomar (Marcus Stollsteimer).

File rdoc_for_array_and_string_slice_2_v1.patch added
File rdoc_for_array_and_string_slice_2_v2.patch added

Hi Eric,

thank you, there are definitely some improvements here.

But: in my opinion the documentation is still unsatisfactory.
Having the examples surely helps in making clear that the
behavior is desired, but there is still no explanation.

The discussions I linked to in the original bug report
show that people are puzzled by the seemingly illogical
behavior, specifically that the same index value sometimes
does lie in the valid range and sometimes does not:

  a = [1, 2, 3, 4]
  a[4]              #=> nil
  a[4, 1]           #=> []    (why?!)

Providing a consistent explanation really would help.

I attached two alternative suggestions for consideration.

Regards,
Marcus

----------------------------------------
Bug #6680: Unclear rdoc for Array and String slicing
https://bugs.ruby-lang.org/issues/6680#change-27802

Author: stomar (Marcus Stollsteimer)
Status: Closed
Priority: Normal
Assignee: drbrain (Eric Hodel)
Category: DOC
Target version: 2.0.0
ruby -v: ruby 1.9.3p243 (2012-06-28 revision 36244) [i686-linux]


=begin
Slicing of arrays and strings specifying start/length or using a range is not documented well, and often leads to confusion, see for example

<http://stackoverflow.com/questions/3568222/array-slicing-in-ruby-looking-for-explanation-for-illogical-behaviour-taken-fr>

or

<http://www.ruby-forum.com/topic/1393096#990065>

The attached patch tries to clarify the documentation.
=end



-- 
http://bugs.ruby-lang.org/