Issue #6106 has been reported by Perry Metzger.

----------------------------------------
Bug #6106: Ruby documentation ambiguous about mixed sign ranges in indexes
https://bugs.ruby-lang.org/issues/6106

Author: Perry Metzger
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11]


Although syntax like s[3..-1] is legal and will return element 4 to the end of the indexed object, the documentation is ambiguous and does not make it clear that this is legal. (Apparently the documentation in 1.4 and before did indicate it but the documentation for 1.9 does not.)

There is a sole example of such indexing in the documentation for String, but it is an invalid slice and returns nil.

I would suggest that appropriate examples be added to the documentation (something like:

> s = "0123456789"
=> "0123456789"
> s[2..-1]
=> "23456789"

) and that some indication be made that the content of the range is not important (2..-1 is an empty range) but rather only the begin and end attributes of the range are used in determining the slice.

(And this is actually a problem -- I have checked The Ruby Programming Language, various official examples and the official documentation and there is nowhere an example of this even though it is well understood to be a reasonable way to slice from an index to the end of a string.)


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