diff --git a/ChangeLog b/ChangeLog index 699e3a3d85..2b5e6aa67c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sat Feb 23 12:35:00 2013 Zachary Scott + + * array.c: Document #<=> return values and formatting + * bignum.c: ditto + * file.c: ditto + * object.c: ditto + * numeric.c: ditto + * rational.c: ditto + * string.c: ditto + * time.c: ditto + Sat Feb 23 10:50:00 2013 Zachary Scott * array.c (rb_ary_diff, rb_ary_and, rb_ary_or): Document return order diff --git a/array.c b/array.c index ba93a050ed..84c386cefa 100644 --- a/array.c +++ b/array.c @@ -3703,6 +3703,8 @@ recursive_cmp(VALUE ary1, VALUE ary2, int recur) * Comparison --- Returns an integer (+-1+, +0+, or +1) 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 diff --git a/bignum.c b/bignum.c index 8601d80342..54dd75cf89 100644 --- a/bignum.c +++ b/bignum.c @@ -1520,9 +1520,11 @@ rb_integer_float_eq(VALUE x, VALUE y) * call-seq: * big <=> numeric -> -1, 0, +1 or nil * - * Comparison---Returns -1, 0, or +1 depending on whether big is - * less than, equal to, or greater than numeric. This is the - * basis for the tests in Comparable. + * Comparison---Returns -1, 0, or +1 depending on whether +big+ is + * less than, equal to, or greater than +numeric+. This is the + * basis for the tests in Comparable. + * + * +nil+ is returned if the two values are incomparable. * */ diff --git a/file.c b/file.c index 69b5a7cf4b..6742cf022e 100644 --- a/file.c +++ b/file.c @@ -326,8 +326,10 @@ static struct timespec stat_mtimespec(struct stat *st); * call-seq: * stat <=> other_stat -> -1, 0, 1, nil * - * Compares File::Stat objects by comparing their - * respective modification times. + * Compares File::Stat objects by comparing their respective modification + * times. + * + * +nil+ is returned if the two values are incomparable. * * f1 = File.new("f1", "w") * sleep 1 diff --git a/numeric.c b/numeric.c index 5c629d79c9..fe85d6cc31 100644 --- a/numeric.c +++ b/numeric.c @@ -1038,10 +1038,10 @@ num_eql(VALUE x, VALUE y) /* * call-seq: - * num <=> other -> 0 or nil + * number <=> other -> 0 or nil * - * Returns zero if num equals other, nil - * otherwise. + * Returns zero if +number+ equals +other+, otherwise +nil+ is returned if the + * two values are incomparable. */ static VALUE @@ -1129,13 +1129,15 @@ rb_dbl_cmp(double a, double b) /* * call-seq: - * flt <=> real -> -1, 0, +1 or nil + * float <=> real -> -1, 0, +1 or nil + * + * Returns -1, 0, +1 or nil depending on whether +float+ is less than, equal + * to, or greater than +real+. This is the basis for the tests in Comparable. * - * Returns -1, 0, +1 or nil depending on whether flt is less - * than, equal to, or greater than real. This is the basis for - * the tests in Comparable. * The result of NaN <=> NaN is undefined, so the * implementation-dependent value is returned. + * + * +nil+ is returned if the two values are incomparable. */ static VALUE @@ -3042,10 +3044,11 @@ fix_equal(VALUE x, VALUE y) * call-seq: * fix <=> numeric -> -1, 0, +1 or nil * - * Comparison---Returns -1, 0, +1 or nil depending on whether - * fix is less than, equal to, or greater than - * numeric. This is the basis for the tests in - * Comparable. + * Comparison---Returns -1, 0, +1 or nil depending on whether +fix+ is less + * than, equal to, or greater than +numeric+. This is the basis for the tests + * in Comparable. + * + * +nil+ is returned if the two values are incomparable. */ static VALUE diff --git a/object.c b/object.c index 76ff316543..3da19cdf3d 100644 --- a/object.c +++ b/object.c @@ -1540,13 +1540,14 @@ rb_mod_gt(VALUE mod, VALUE arg) /* * call-seq: - * mod <=> other_mod -> -1, 0, +1, or nil + * module <=> other_module -> -1, 0, +1, or nil * - * Comparison---Returns -1 if mod includes other_mod, 0 if - * mod is the same as other_mod, and +1 if mod is - * included by other_mod. Returns nil if mod - * has no relationship with other_mod or if other_mod is - * not a module. + * Comparison---Returns -1, 0, +1 or nil depending on whether +module+ + * includes +other_module+, they are the same, or if +module+ is included by + * +other_module+. This is the basis for the tests in Comparable. + * + * Returns +nil+ if +module+ has no relationship with +other_module+, if + * +other_module+ is not a module, or if the two values are incomparable. */ static VALUE diff --git a/rational.c b/rational.c index 0cba54e281..a78b3202ec 100644 --- a/rational.c +++ b/rational.c @@ -1024,10 +1024,12 @@ nurat_expt(VALUE self, VALUE other) /* * call-seq: - * rat <=> numeric -> -1, 0, +1 or nil + * rational <=> numeric -> -1, 0, +1 or nil * * Performs comparison and returns -1, 0, or +1. * + * +nil+ is returned if the two values are incomparable. + * * Rational(2, 3) <=> Rational(2, 3) #=> 0 * Rational(5) <=> 5 #=> 0 * Rational(2,3) <=> Rational(1,3) #=> 1 diff --git a/string.c b/string.c index 3d4fd37b5a..cbfac397fc 100644 --- a/string.c +++ b/string.c @@ -2358,20 +2358,22 @@ rb_str_eql(VALUE str1, VALUE str2) /* * call-seq: - * str <=> other_str -> -1, 0, +1 or nil + * string <=> other_string -> -1, 0, +1 or nil * - * Comparison---Returns -1 if other_str is greater than, 0 if - * other_str is equal to, and +1 if other_str is less than - * str. If the strings are of different lengths, and the strings are - * equal when compared up to the shortest length, then the longer string is - * considered greater than the shorter one. In older versions of Ruby, setting - * $= allowed case-insensitive comparisons; this is now deprecated - * in favor of using String#casecmp. + * + * Comparison---Returns -1, 0, +1 or nil depending on whether +string+ is less + * than, equal to, or greater than +other_string+. + * + * +nil+ is returned if the two values are incomparable. + * + * If the strings are of different lengths, and the strings are equal when + * compared up to the shortest length, then the longer string is considered + * greater than the shorter one. * * <=> is the basis for the methods <, - * <=, >, >=, and between?, - * included from module Comparable. The method - * String#== does not use Comparable#==. + * <=, >, >=, and + * between?, included from module Comparable. The method + * String#== does not use Comparable#==. * * "abcdef" <=> "abcde" #=> 1 * "abcdef" <=> "abcdef" #=> 0 @@ -7946,9 +7948,15 @@ sym_succ(VALUE sym) /* * call-seq: * - * str <=> other -> -1, 0, +1 or nil + * symbol <=> other_symbol -> -1, 0, +1 or nil * - * Compares _sym_ with _other_ in string form. + * Compares +symbol+ with +other_symbol+ after calling #to_s on each of the + * symbols. Returns -1, 0, +1 or nil depending on whether +symbol+ is less + * than, equal to, or greater than +other_symbol+. + * + * +nil+ is returned if the two values are incomparable. + * + * See String#<=> for more information. */ static VALUE diff --git a/time.c b/time.c index 765dc31194..77cac95621 100644 --- a/time.c +++ b/time.c @@ -3334,10 +3334,12 @@ time_subsec(VALUE time) * call-seq: * time <=> other_time -> -1, 0, +1 or nil * - * Comparison---Compares _time_ with +other_time+. - * The return value is ++1+ if _time_ is greater than - * +other_time+, +0+ if _time_ is equal to +other_time+ and - * +-1+ if _time_ is smaller than +other_time+. + * Comparison---Compares +time+ with +other_time+. + * + * -1, 0, +1 or nil depending on whether +time+ is less than, equal to, or + * greater than +other_time+. + * + * +nil+ is returned if the two values are incomparable. * * t = Time.now #=> 2007-11-19 08:12:12 -0600 * t2 = t + 2592000 #=> 2007-12-19 08:12:12 -0600