ruby-changes:24277
From: drbrain <ko1@a...>
Date: Fri, 6 Jul 2012 06:50:44 +0900 (JST)
Subject: [ruby-changes:24277] drbrain:r36328 (trunk): * array.c (rb_ary_aref): Added a description of the behavior of
drbrain 2012-07-06 06:50:13 +0900 (Fri, 06 Jul 2012) New Revision: 36328 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36328 Log: * array.c (rb_ary_aref): Added a description of the behavior of index positioning. [Bug #6680] * array.c (rb_ary_aset): ditto. Reordered sentences for clarity. * string.c (rb_str_aref_m): Added a description of the behavior of index positioning Modified files: trunk/ChangeLog trunk/array.c trunk/string.c Index: array.c =================================================================== --- array.c (revision 36327) +++ array.c (revision 36328) @@ -1016,7 +1016,9 @@ * elements, or returns a subarray specified by +range+ of indices. * * Negative indices count backward from the end of the array (-1 is the last - * element). + * element). For +start+ and +range+ cases the starting index is just before + * an element. Additionally, an empty array is returned when the starting + * index for an element range is at the end of the array. * * Returns +nil+ if the index (or starting index) are out of range. * @@ -1030,7 +1032,7 @@ * a[-3, 3] #=> [ "c", "d", "e" ] * # special cases * a[5] #=> nil - * a[6] #=> nil + * a[6, 1] #=> nil * a[5, 1] #=> [] * a[5..10] #=> [] * @@ -1436,9 +1438,12 @@ * specified by the +range+ of indices. * * If indices are greater than the current capacity of the array, the array - * grows automatically. Negative indices will count backward from the end of - * the array. Inserts elements if +length+ is zero. + * grows automatically. Elements are inserted into the array at +start+ if + * +length+ is zero. * + * Negative indices will count backward from the end of the array. For + * +start+ and +range+ cases the starting index is just before an element. + * * An IndexError is raised if a negative index points past the beginning of * the array. * Index: ChangeLog =================================================================== --- ChangeLog (revision 36327) +++ ChangeLog (revision 36328) @@ -1,3 +1,11 @@ +Fri Jul 6 06:49:50 2012 Eric Hodel <drbrain@s...> + + * array.c (rb_ary_aref): Added a description of the behavior of + index positioning. [Bug #6680] + * array.c (rb_ary_aset): ditto. Reordered sentences for clarity. + * string.c (rb_str_aref_m): Added a description of the behavior of + index positioning + Fri Jul 6 05:38:44 2012 Eric Hodel <drbrain@s...> * string.c (rb_str_bytesize): Improve documentation. Patch by Oscar Index: string.c =================================================================== --- string.c (revision 36327) +++ string.c (revision 36328) @@ -3223,10 +3223,15 @@ * Element Reference --- If passed a single +index+, returns a substring of * one character at that index. If passed a +start+ index and a +length+, * returns a substring containing +length+ characters starting at the - * +index+. If passed a range, its beginning and end are interpreted as - * offsets delimiting the substring to be returned. In these three cases, if - * an index is negative, it is counted from the end of the string. + * +index+. If passed a +range+, its beginning and end are interpreted as + * offsets delimiting the substring to be returned. * + * In these three cases, if an index is negative, it is counted from the end + * of the string. For the +start+ and +range+ cases the starting index + * is just before a character and an index matching the string's size. + * Additionally, an empty string is returned when the starting index for a + * character range is at the end of the string. + * * Returns +nil+ if the initial index falls outside the string or the length * is negative. * -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/