Project

General

Profile

Actions

Bug #6106

closed

Ruby documentation ambiguous about mixed sign ranges in indexes

Added by perry (Perry Metzger) about 12 years ago. Updated about 12 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11]
Backport:
[ruby-core:43035]

Description

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.)

Actions #1

Updated by marcandre (Marc-Andre Lafortune) about 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r34927.
Perry, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • string.c (rb_str_aref): Improve rdoc, as per [bug #6106]
Actions

Also available in: Atom PDF

Like0
Like0