Example #1
0
static void
range_init(VALUE range, VALUE beg, VALUE end, int exclude_end)
{
    VALUE args[2];

    args[0] = beg;
    args[1] = end;

    if (!FIXNUM_P(beg) || !FIXNUM_P(end)) {
	VALUE v;

	v = rb_rescue(range_check, (VALUE)args, range_failed, 0);
	if (NIL_P(v))
	    range_failed();
    }

    SET_EXCL(range, exclude_end);
    GC_WB(&RANGE_BEG(range), beg);
    GC_WB(&RANGE_END(range), end);
}
Example #2
0
static void
range_init(VALUE range, VALUE beg, VALUE end, int exclude_end)
{
    VALUE args[2];

    args[0] = beg;
    args[1] = end;

    if (!FIXNUM_P(beg) || !FIXNUM_P(end)) {
	VALUE v;

	v = rb_rescue(range_check, (VALUE)args, range_failed, 0);
	if (NIL_P(v))
	    range_failed();
    }

    SET_EXCL(range, exclude_end);
    RSTRUCT(range)->as.ary[0] = beg;
    RSTRUCT(range)->as.ary[1] = end;
}
Example #3
0
static void
step_init(
  VALUE self,
  VALUE beg,
  VALUE end,
  VALUE step,
  VALUE len,
  VALUE excl
)
{
    if (RTEST(len)) {
        if (!(FIXNUM_P(len) || TYPE(len)==T_BIGNUM)) {
            rb_raise(rb_eArgError, "length must be Integer");
        }
        if (RTEST(rb_funcall(len,rb_intern("<"),1,INT2FIX(0)))) {
            rb_raise(rb_eRangeError,"length must be non negative");
        }
    }
    rb_ivar_set(self, id_beg, beg);
    rb_ivar_set(self, id_end, end);
    rb_ivar_set(self, id_len, len);
    rb_ivar_set(self, id_step, step);
    SET_EXCL(self, excl);
}