1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* string.c (rb_str_cmp_m): return nil if str2 does not respond to

both "to_str" and "<=>".

* compar.c (cmp_gt): return nil if "<=>" returns nil (means
  incomparable).

* compar.c (cmp_ge): ditto.

* compar.c (cmp_lt): ditto.

* compar.c (cmp_between): use RTEST(), since cmp_lt and cmp_gt may
  return nil.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-02-20 20:40:20 +00:00
parent 697462490a
commit 64db238388
4 changed files with 41 additions and 12 deletions

View file

@ -50,7 +50,7 @@ cmp_gt(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
if (NIL_P(c)) return Qnil;
if (rb_cmpint(c) > 0) return Qtrue;
return Qfalse;
}
@ -61,7 +61,7 @@ cmp_ge(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
if (NIL_P(c)) return Qnil;
if (rb_cmpint(c) >= 0) return Qtrue;
return Qfalse;
}
@ -72,7 +72,7 @@ cmp_lt(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
if (NIL_P(c)) return Qnil;
if (rb_cmpint(c) < 0) return Qtrue;
return Qfalse;
}
@ -83,7 +83,7 @@ cmp_le(x, y)
{
VALUE c = rb_funcall(x, cmp, 1, y);
if (NIL_P(c)) return Qfalse;
if (NIL_P(c)) return Qnil;
if (rb_cmpint(c) <= 0) return Qtrue;
return Qfalse;
}
@ -92,8 +92,8 @@ static VALUE
cmp_between(x, min, max)
VALUE x, min, max;
{
if (cmp_lt(x, min)) return Qfalse;
if (cmp_gt(x, max)) return Qfalse;
if (RTEST(cmp_lt(x, min))) return Qfalse;
if (RTEST(cmp_gt(x, max))) return Qfalse;
return Qtrue;
}