diff options
Diffstat (limited to 'compar.c')
| -rw-r--r-- | compar.c | 60 |
1 files changed, 46 insertions, 14 deletions
@@ -24,8 +24,8 @@ rb_cmp(VALUE x, VALUE y) return rb_funcallv(x, idCmp, 1, &y); } -void -rb_cmperr(VALUE x, VALUE y) +static VALUE +cmperr_subject(VALUE y) { VALUE classname; @@ -35,10 +35,25 @@ rb_cmperr(VALUE x, VALUE y) else { classname = rb_obj_class(y); } + return classname; +} + +void +rb_cmperr(VALUE x, VALUE y) +{ + VALUE classname = cmperr_subject(y); rb_raise(rb_eArgError, "comparison of %"PRIsVALUE" with %"PRIsVALUE" failed", rb_obj_class(x), classname); } +void +rb_cmperr_reason(VALUE x, VALUE y, const char *reason) +{ + VALUE classname = cmperr_subject(y); + rb_raise(rb_eArgError, "comparison of %"PRIsVALUE" with %"PRIsVALUE" failed: %s", + rb_obj_class(x), classname, reason); +} + static VALUE invcmp_recursive(VALUE x, VALUE y, int recursive) { @@ -95,10 +110,13 @@ cmpint(VALUE x, VALUE y) /* * call-seq: - * obj > other -> true or false + * self > other -> true or false * - * Compares two objects based on the receiver's <code><=></code> - * method, returning true if it returns a value greater than 0. + * Returns whether +self+ is "greater than" +other+; + * equivalent to <tt>(self <=> other) > 0</tt>: + * + * 'foo' > 'foo' # => false + * 'food' > 'foo' # => true */ static VALUE @@ -109,10 +127,15 @@ cmp_gt(VALUE x, VALUE y) /* * call-seq: - * obj >= other -> true or false + * self >= other -> true or false + * + * Returns whether +self+ is "greater than or equal to" +other+; + * equivalent to <tt>(self <=> other) >= 0</tt>: + * + * 'food' >= 'foo' # => true + * 'foo' >= 'foo' # => true + * 'foo' >= 'food' # => false * - * Compares two objects based on the receiver's <code><=></code> - * method, returning true if it returns a value greater than or equal to 0. */ static VALUE @@ -123,10 +146,14 @@ cmp_ge(VALUE x, VALUE y) /* * call-seq: - * obj < other -> true or false + * self < other -> true or false + * + * Returns whether +self+ is "less than" +other+; + * equivalent to <tt>(self <=> other) < 0</tt>: + * + * 'foo' < 'foo' # => false + * 'foo' < 'food' # => true * - * Compares two objects based on the receiver's <code><=></code> - * method, returning true if it returns a value less than 0. */ static VALUE @@ -137,10 +164,15 @@ cmp_lt(VALUE x, VALUE y) /* * call-seq: - * obj <= other -> true or false + * self <= other -> true or false + * + * Returns whether +self+ is "less than or equal to" +other+; + * equivalent to <tt>(self <=> other) <= 0</tt>: + * + * 'foo' <= 'foo' # => true + * 'foo' <= 'food' # => true + * 'food' <= 'foo' # => false * - * Compares two objects based on the receiver's <code><=></code> - * method, returning true if it returns a value less than or equal to 0. */ static VALUE |
