[前][次][番号順一覧][スレッド一覧]

ruby-changes:24247

From: drbrain <ko1@a...>
Date: Wed, 4 Jul 2012 08:30:06 +0900 (JST)
Subject: [ruby-changes:24247] drbrain:r36298 (trunk): * array.c (rb_ary_aref): Updated documentation to indicate the

drbrain	2012-07-04 08:29:56 +0900 (Wed, 04 Jul 2012)

  New Revision: 36298

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36298

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/string.c

Index: array.c
===================================================================
--- array.c	(revision 36297)
+++ array.c	(revision 36298)
@@ -1011,14 +1011,15 @@
  *     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"
  *     a[6]                   #=> nil
@@ -1029,6 +1030,7 @@
  *     a[-3, 3]               #=> [ "c", "d", "e" ]
  *     # special cases
  *     a[5]                   #=> nil
+ *     a[6]                   #=> nil
  *     a[5, 1]                #=> []
  *     a[5..10]               #=> []
  *
@@ -1430,8 +1432,8 @@
  *     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 @@
  *     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
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36297)
+++ ChangeLog	(revision 36298)
@@ -1,3 +1,13 @@
+Wed Jul  4 08:29:31 2012  Eric Hodel  <drbrain@s...>
+
+	* 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@s...>
 
 	* test/zlib/test_zlib.rb (test_inflate_partial_input):  Added test for
Index: string.c
===================================================================
--- string.c	(revision 36297)
+++ string.c	(revision 36298)
@@ -3202,49 +3202,64 @@
 
 /*
  *  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
  */

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]