summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-09 17:33:47 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-09 17:33:47 +0000
commite030b4ee791a082c137f2bf55749c5105fecbcb7 (patch)
treebd0c86303cde52b76ad8b040d1a80fae389c8dbc /array.c
parent363e189a9685c7b3fde35ad1ce14a44ad2267e87 (diff)
downloadruby-e030b4ee791a082c137f2bf55749c5105fecbcb7.tar.gz
* array.c: rdoc clarification for <=>
* file.c: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/array.c b/array.c
index 775fb243bd..088a9a5f1a 100644
--- a/array.c
+++ b/array.c
@@ -3866,21 +3866,26 @@ recursive_cmp(VALUE ary1, VALUE ary2, int recur)
* Comparison --- Returns an integer (+-1+, +0+, or <code>+1</code>) if this
* array is less than, equal to, or greater than +other_ary+.
*
- * +nil+ is returned if the two values are incomparable.
- *
* Each object in each array is compared (using the <=> operator).
*
- * Arrays are compared in an "element-wise" manner; the first two elements
- * that are not equal will determine the return value for the whole
- * comparison.
+ * Arrays are compared in an "element-wise" manner; the first element of +ary+
+ * is compared with the first one of +other_ary+ using the <=> operator, then
+ * each of the second elements, etc...
+ * As soon as the result of any such comparison is non zero (i.e. the two
+ * corresponding elements are not equal), that result is returned for the
+ * whole array comparison.
*
- * If all the values are equal, then the return is based on a comparison of
+ * If all the elements are equal, then the result is based on a comparison of
* the array lengths. Thus, two arrays are "equal" according to Array#<=> if,
* and only if, they have the same length and the value of each element is
* equal to the value of the corresponding element in the other array.
*
+ * +nil+ is returned if the +other_ary+ is not an array or if the comparison
+ * of two elements returned +nil+.
+ *
* [ "a", "a", "c" ] <=> [ "a", "b", "c" ] #=> -1
* [ 1, 2, 3, 4, 5, 6 ] <=> [ 1, 2 ] #=> +1
+ * [ 1, 2 ] <=> [ 1, :two ] #=> nil
*
*/