/* * call-seq: * range === obj => true or false * range.member?(val) => true or false * range.include?(val) => true or false * */ mrb_value mrb_range_include(mrb_state *mrb, mrb_value range) { mrb_value val; struct RRange *r = mrb_range_ptr(range); mrb_value beg, end; mrb_get_args(mrb, "o", &val); beg = r->edges->beg; end = r->edges->end; if (r_le(mrb, beg, val)) { /* beg <= val */ if (r->excl) { if (r_gt(mrb, end, val)) return mrb_true_value(); /* end > val */ } else { if (r_ge(mrb, end, val)) return mrb_true_value(); /* end >= val */ } } return mrb_false_value(); }
static void range_each_func(VALUE range, rb_block_call_func *func, VALUE arg) { int c; VALUE b = RANGE_BEG(range); VALUE e = RANGE_END(range); VALUE v = b; if (EXCL(range)) { while (r_lt(v, e)) { (*func) (v, arg, 0, 0, 0); v = rb_funcall(v, id_succ, 0, 0); } } else { while ((c = r_le(v, e)) != Qfalse) { (*func) (v, arg, 0, 0, 0); if (c == (int)INT2FIX(0)) break; v = rb_funcall(v, id_succ, 0, 0); } } }