/* * rng === anObject -> true or false * --- * Returns true if anObject is an element of rng, false otherwise. * Conveniently, === is the comparison operator used by case * statements. * case 79 * when 1..50 then print "low\n" * when 51..75 then print "medium\n" * when 76..100 then print "high\n" * end * produces: * high */ static VALUE range_eqq(range, obj) VALUE range, obj; { VALUE beg, end; beg = rb_ivar_get(range, id_beg); end = rb_ivar_get(range, id_end); if (FIXNUM_P(beg) && FIXNUM_P(obj) && FIXNUM_P(end)) { if (FIX2LONG(beg) <= FIX2LONG(obj)) { if (EXCL(range)) { if (FIX2LONG(obj) < FIX2LONG(end)) return Qtrue; } else { if (FIX2LONG(obj) <= FIX2LONG(end)) return Qtrue; } } return Qfalse; } else if (RTEST(rb_funcall(beg, rb_intern("<="), 1, obj))) { if (EXCL(range)) { if (RTEST(rb_funcall(end, rb_intern(">"), 1, obj))) return Qtrue; } else { if (RTEST(rb_funcall(end, rb_intern(">="), 1, obj))) return Qtrue; } } return Qfalse; }