* 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:
parent
ad187bde9c
commit
ab63d24b04
10
ChangeLog
10
ChangeLog
@ -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>
|
Wed Jul 4 07:05:59 2012 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* test/zlib/test_zlib.rb (test_inflate_partial_input): Added test for
|
* test/zlib/test_zlib.rb (test_inflate_partial_input): Added test for
|
||||||
|
22
array.c
22
array.c
@ -1011,13 +1011,14 @@ rb_ary_subseq(VALUE ary, long beg, long len)
|
|||||||
* ary.slice(start, length) -> new_ary or nil
|
* ary.slice(start, length) -> new_ary or nil
|
||||||
* ary.slice(range) -> new_ary or nil
|
* ary.slice(range) -> new_ary or nil
|
||||||
*
|
*
|
||||||
* Element Reference---Returns the element at +index+,
|
* Element Reference --- Returns the element at +index+, or returns a
|
||||||
* or returns a subarray starting at +start+ and
|
* subarray starting at the +start+ index and continuing for +length+
|
||||||
* continuing for +length+ elements, or returns a subarray
|
* elements, or returns a subarray specified by +range+ of indices.
|
||||||
* specified by +range+.
|
*
|
||||||
* Negative indices count backward from the end of the
|
* Negative indices count backward from the end of the array (-1 is the last
|
||||||
* array (-1 is the last element). Returns +nil+ if the index
|
* element).
|
||||||
* (or starting index) are out of range.
|
*
|
||||||
|
* Returns +nil+ if the index (or starting index) are out of range.
|
||||||
*
|
*
|
||||||
* a = [ "a", "b", "c", "d", "e" ]
|
* a = [ "a", "b", "c", "d", "e" ]
|
||||||
* a[2] + a[0] + a[1] #=> "cab"
|
* 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" ]
|
* a[-3, 3] #=> [ "c", "d", "e" ]
|
||||||
* # special cases
|
* # special cases
|
||||||
* a[5] #=> nil
|
* a[5] #=> nil
|
||||||
|
* a[6] #=> nil
|
||||||
* a[5, 1] #=> []
|
* a[5, 1] #=> []
|
||||||
* a[5..10] #=> []
|
* 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
|
* 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
|
* Element Assignment --- Sets the element at +index+, or replaces a subarray
|
||||||
* from +start+ for +length+ elements, or replaces a subarray specified by
|
* from the +start+ index for +length+ elements, or replaces a subarray
|
||||||
* +range+.
|
* specified by the +range+ of indices.
|
||||||
*
|
*
|
||||||
* If indices are greater than the current capacity of the array, the array
|
* If indices are greater than the current capacity of the array, the array
|
||||||
* grows automatically. Negative indices will count backward from the end of
|
* 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] = "Z" #=> ["A", "Z"]
|
||||||
* a[1..-1] = nil #=> ["A", nil]
|
* a[1..-1] = nil #=> ["A", nil]
|
||||||
* a[1..-1] = [] #=> ["A"]
|
* a[1..-1] = [] #=> ["A"]
|
||||||
|
* a[0, 0] = [ 1, 2 ] #=> [1, 2, "A"]
|
||||||
|
* a[3, 0] = "B" #=> [1, 2, "A", "B"]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
61
string.c
61
string.c
@ -3202,49 +3202,64 @@ rb_str_aref(VALUE str, VALUE indx)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* str[fixnum] -> new_str or nil
|
* str[index] -> new_str or nil
|
||||||
* str[fixnum, fixnum] -> new_str or nil
|
* str[start, length] -> new_str or nil
|
||||||
* str[range] -> new_str or nil
|
* str[range] -> new_str or nil
|
||||||
* str[regexp] -> new_str or nil
|
* str[regexp] -> new_str or nil
|
||||||
* str[regexp, fixnum] -> new_str or nil
|
* str[regexp, capture] -> new_str or nil
|
||||||
* str[other_str] -> new_str or nil
|
* str[match_str] -> new_str or nil
|
||||||
* str.slice(fixnum) -> new_str or nil
|
* str.slice(index) -> new_str or nil
|
||||||
* str.slice(fixnum, fixnum) -> new_str or nil
|
* str.slice(start, length) -> new_str or nil
|
||||||
* str.slice(range) -> new_str or nil
|
* str.slice(range) -> new_str or nil
|
||||||
* str.slice(regexp) -> new_str or nil
|
* str.slice(regexp) -> new_str or nil
|
||||||
* str.slice(regexp, fixnum) -> new_str or nil
|
* str.slice(regexp, capture) -> new_str or nil
|
||||||
* str.slice(regexp, capname) -> new_str or nil
|
* str.slice(match_str) -> new_str or nil
|
||||||
* str.slice(other_str) -> new_str or nil
|
|
||||||
*
|
*
|
||||||
* Element Reference---If passed a single <code>Fixnum</code>, returns a
|
* Element Reference --- If passed a single +index+, returns a substring of
|
||||||
* substring of one character at that position. If passed two <code>Fixnum</code>
|
* one character at that index. If passed a +start+ index and a +length+,
|
||||||
* objects, returns a substring starting at the offset given by the first, and
|
* returns a substring containing +length+ characters starting at the
|
||||||
* with a length given by the second. If passed a range, its beginning and end
|
* +index+. If passed a range, its beginning and end are interpreted as
|
||||||
* are interpreted as offsets delimiting the substring to be returned. In all
|
* offsets delimiting the substring to be returned. In these three cases, if
|
||||||
* three cases, if an offset is negative, it is counted from the end of <i>str</i>.
|
* an index is negative, it is counted from the end of the string.
|
||||||
* Returns <code>nil</code> if the initial offset falls outside the string or
|
|
||||||
* the length is negative.
|
|
||||||
*
|
*
|
||||||
* If a <code>Regexp</code> is supplied, the matching portion of <i>str</i> is
|
* Returns +nil+ if the initial index falls outside the string or the length
|
||||||
* returned. If a numeric or name parameter follows the regular expression, that
|
* is negative.
|
||||||
* component of the <code>MatchData</code> is returned instead. If a
|
*
|
||||||
* <code>String</code> is given, that string is returned if it occurs in
|
* If a +Regexp+ is supplied, the matching portion of the string is
|
||||||
* <i>str</i>. In both cases, <code>nil</code> is returned if there is no
|
* returned. If a +capture+ follows the regular expression, which may be a
|
||||||
* match.
|
* 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 = "hello there"
|
||||||
|
*
|
||||||
* a[1] #=> "e"
|
* a[1] #=> "e"
|
||||||
* a[2, 3] #=> "llo"
|
* a[2, 3] #=> "llo"
|
||||||
* a[2..3] #=> "ll"
|
* a[2..3] #=> "ll"
|
||||||
|
*
|
||||||
* a[-3, 2] #=> "er"
|
* a[-3, 2] #=> "er"
|
||||||
* a[7..-2] #=> "her"
|
* a[7..-2] #=> "her"
|
||||||
* a[-4..-2] #=> "her"
|
* a[-4..-2] #=> "her"
|
||||||
* a[-2..-4] #=> ""
|
* a[-2..-4] #=> ""
|
||||||
|
*
|
||||||
|
* a[11, 0] #=> ""
|
||||||
|
* a[11] #=> nil
|
||||||
|
* a[12, 0] #=> nil
|
||||||
* a[12..-1] #=> nil
|
* a[12..-1] #=> nil
|
||||||
|
*
|
||||||
* a[/[aeiou](.)\1/] #=> "ell"
|
* a[/[aeiou](.)\1/] #=> "ell"
|
||||||
* a[/[aeiou](.)\1/, 0] #=> "ell"
|
* a[/[aeiou](.)\1/, 0] #=> "ell"
|
||||||
* a[/[aeiou](.)\1/, 1] #=> "l"
|
* a[/[aeiou](.)\1/, 1] #=> "l"
|
||||||
* a[/[aeiou](.)\1/, 2] #=> nil
|
* 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["lo"] #=> "lo"
|
||||||
* a["bye"] #=> nil
|
* a["bye"] #=> nil
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user