summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-03 23:29:56 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-03 23:29:56 +0000
commitab63d24b049db35df4a68770b9fed6a11696961a (patch)
tree250d77b77f97edf58ca9c33c50d196ad70f1e2f4 /array.c
parentad187bde9ccbf1755d9c4dd4897f648e6666ae19 (diff)
* 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
Diffstat (limited to 'array.c')
-rw-r--r--array.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/array.c b/array.c
index f92bfd3985..170c8d2b63 100644
--- a/array.c
+++ b/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(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