diff options
Diffstat (limited to 'compar.c')
-rw-r--r-- | compar.c | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -50,7 +50,7 @@ VALUE rb_invcmp(VALUE x, VALUE y) { VALUE invcmp = rb_exec_recursive(invcmp_recursive, x, y); - if (invcmp == Qundef || NIL_P(invcmp)) { + if (NIL_OR_UNDEF_P(invcmp)) { return Qnil; } else { @@ -187,6 +187,12 @@ cmp_between(VALUE x, VALUE min, VALUE max) * 'd'.clamp('a', 'f') #=> 'd' * 'z'.clamp('a', 'f') #=> 'f' * + * If _min_ is +nil+, it is considered smaller than _obj_, + * and if _max_ is +nil+, it is considered greater than _obj_. + * + * -20.clamp(0, nil) #=> 0 + * 523.clamp(nil, 100) #=> 100 + * * In <code>(range)</code> form, returns _range.begin_ if _obj_ * <code><=></code> _range.begin_ is less than zero, _range.end_ * if _obj_ <code><=></code> _range.end_ is greater than zero, and @@ -229,7 +235,7 @@ cmp_clamp(int argc, VALUE *argv, VALUE x) } } if (!NIL_P(min) && !NIL_P(max) && cmpint(min, max) > 0) { - rb_raise(rb_eArgError, "min argument must be smaller than max argument"); + rb_raise(rb_eArgError, "min argument must be less than or equal to max argument"); } if (!NIL_P(min)) { @@ -257,25 +263,28 @@ cmp_clamp(int argc, VALUE *argv, VALUE x) * <code>==</code>, <code>>=</code>, and <code>></code>) and the * method <code>between?</code>. * - * class SizeMatters + * class StringSorter * include Comparable + * * attr :str * def <=>(other) * str.size <=> other.str.size * end + * * def initialize(str) * @str = str * end + * * def inspect * @str * end * end * - * s1 = SizeMatters.new("Z") - * s2 = SizeMatters.new("YY") - * s3 = SizeMatters.new("XXX") - * s4 = SizeMatters.new("WWWW") - * s5 = SizeMatters.new("VVVVV") + * s1 = StringSorter.new("Z") + * s2 = StringSorter.new("YY") + * s3 = StringSorter.new("XXX") + * s4 = StringSorter.new("WWWW") + * s5 = StringSorter.new("VVVVV") * * s1 < s2 #=> true * s4.between?(s1, s3) #=> false @@ -289,8 +298,8 @@ cmp_clamp(int argc, VALUE *argv, VALUE x) * - #<: Returns whether +self+ is less than the given object. * - #<=: Returns whether +self+ is less than or equal to the given object. * - #==: Returns whether +self+ is equal to the given object. - * - #>: Returns whether +self+ is greater than or equal to the given object. - * - #>=: Returns whether +self+ is greater than the given object. + * - #>: Returns whether +self+ is greater than the given object. + * - #>=: Returns whether +self+ is greater than or equal to the given object. * - #between?: Returns +true+ if +self+ is between two given objects. * - #clamp: For given objects +min+ and +max+, or range <tt>(min..max)</tt>, returns: * |