1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (rb_ary_aref): Updated documentation to indicate the

starting index is an index into the array or string.  Updated
  examples to show behavior of indexes at the end of an array or
  string.  Based on patch by Marcus Stollsteimer.  [Bug #6680]
* array.c (rb_ary_aset):  ditto.
* string.c (rb_str_aref):  ditto.  Also added descriptive argument
  names to call-seq section.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36298 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2012-07-03 23:29:56 +00:00
parent ad187bde9c
commit ab63d24b04
3 changed files with 65 additions and 36 deletions

View file

@ -1,3 +1,13 @@
Wed Jul 4 08:29:31 2012 Eric Hodel <drbrain@segment7.net>
* array.c (rb_ary_aref): Updated documentation to indicate the
starting index is an index into the array or string. Updated
examples to show behavior of indexes at the end of an array or
string. Based on patch by Marcus Stollsteimer. [Bug #6680]
* array.c (rb_ary_aset): ditto.
* string.c (rb_str_aref): ditto. Also added descriptive argument
names to call-seq section.
Wed Jul 4 07:05:59 2012 Eric Hodel <drbrain@segment7.net>
* test/zlib/test_zlib.rb (test_inflate_partial_input): Added test for

22
array.c
View file

@ -1011,13 +1011,14 @@ rb_ary_subseq(VALUE ary, long beg, long len)
* ary.slice(start, length) -> new_ary or nil
* ary.slice(range) -> new_ary or nil
*
* Element Reference---Returns the element at +index+,
* or returns a subarray starting at +start+ and
* continuing for +length+ elements, or returns a subarray
* specified by +range+.
* Negative indices count backward from the end of the
* array (-1 is the last element). Returns +nil+ if the index
* (or starting index) are out of range.
* Element Reference --- Returns the element at +index+, or returns a
* subarray starting at the +start+ index and continuing for +length+
* 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).
*
* Returns +nil+ if the index (or starting index) are out of range.
*
* a = [ "a", "b", "c", "d", "e" ]
* a[2] + a[0] + a[1] #=> "cab"
@ -1029,6 +1030,7 @@ rb_ary_subseq(VALUE ary, long beg, long len)
* a[-3, 3] #=> [ "c", "d", "e" ]
* # special cases
* a[5] #=> nil
* a[6] #=> nil
* a[5, 1] #=> []
* a[5..10] #=> []
*
@ -1430,8 +1432,8 @@ rb_ary_resize(VALUE ary, long len)
* ary[range] = obj or other_ary or nil -> obj or other_ary or nil
*
* Element Assignment --- Sets the element at +index+, or replaces a subarray
* from +start+ for +length+ elements, or replaces a subarray specified by
* +range+.
* from the +start+ index for +length+ elements, or replaces a subarray
* 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
@ -1451,6 +1453,8 @@ rb_ary_resize(VALUE ary, long len)
* a[-1] = "Z" #=> ["A", "Z"]
* a[1..-1] = nil #=> ["A", nil]
* a[1..-1] = [] #=> ["A"]
* a[0, 0] = [ 1, 2 ] #=> [1, 2, "A"]
* a[3, 0] = "B" #=> [1, 2, "A", "B"]
*/
static VALUE

View file

@ -3202,49 +3202,64 @@ rb_str_aref(VALUE str, VALUE indx)
/*
* call-seq:
* str[fixnum] -> new_str or nil
* str[fixnum, fixnum] -> new_str or nil
* str[range] -> new_str or nil
* str[regexp] -> new_str or nil
* str[regexp, fixnum] -> new_str or nil
* str[other_str] -> new_str or nil
* str.slice(fixnum) -> new_str or nil
* str.slice(fixnum, fixnum) -> new_str or nil
* str.slice(range) -> new_str or nil
* str.slice(regexp) -> new_str or nil
* str.slice(regexp, fixnum) -> new_str or nil
* str.slice(regexp, capname) -> new_str or nil
* str.slice(other_str) -> new_str or nil
* str[index] -> new_str or nil
* str[start, length] -> new_str or nil
* str[range] -> new_str or nil
* str[regexp] -> new_str or nil
* str[regexp, capture] -> new_str or nil
* str[match_str] -> new_str or nil
* str.slice(index) -> new_str or nil
* str.slice(start, length) -> new_str or nil
* str.slice(range) -> new_str or nil
* str.slice(regexp) -> new_str or nil
* str.slice(regexp, capture) -> new_str or nil
* str.slice(match_str) -> new_str or nil
*
* Element Reference---If passed a single <code>Fixnum</code>, returns a
* substring of one character at that position. If passed two <code>Fixnum</code>
* objects, returns a substring starting at the offset given by the first, and
* with a length given by the second. If passed a range, its beginning and end
* are interpreted as offsets delimiting the substring to be returned. In all
* three cases, if an offset is negative, it is counted from the end of <i>str</i>.
* Returns <code>nil</code> if the initial offset falls outside the string or
* the length is negative.
* 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.
*
* If a <code>Regexp</code> is supplied, the matching portion of <i>str</i> is
* returned. If a numeric or name parameter follows the regular expression, that
* component of the <code>MatchData</code> is returned instead. If a
* <code>String</code> is given, that string is returned if it occurs in
* <i>str</i>. In both cases, <code>nil</code> is returned if there is no
* match.
* Returns +nil+ if the initial index falls outside the string or the length
* is negative.
*
* If a +Regexp+ is supplied, the matching portion of the string is
* returned. If a +capture+ follows the regular expression, which may be a
* capture group index or name, follows the regular expression that component
* of the MatchData is returned instead.
*
* If a +match_str+ is given, that string is returned if it occurs in
* the string.
*
* Returns +nil+ if the regular expression does not match or the match string
* cannot be found.
*
* a = "hello there"
*
* a[1] #=> "e"
* a[2, 3] #=> "llo"
* a[2..3] #=> "ll"
*
* a[-3, 2] #=> "er"
* a[7..-2] #=> "her"
* a[-4..-2] #=> "her"
* a[-2..-4] #=> ""
*
* a[11, 0] #=> ""
* a[11] #=> nil
* a[12, 0] #=> nil
* a[12..-1] #=> nil
*
* a[/[aeiou](.)\1/] #=> "ell"
* a[/[aeiou](.)\1/, 0] #=> "ell"
* a[/[aeiou](.)\1/, 1] #=> "l"
* a[/[aeiou](.)\1/, 2] #=> nil
*
* a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] #=> "l"
* a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "vowel"] #=> "e"
*
* a["lo"] #=> "lo"
* a["bye"] #=> nil
*/