method

each

ruby latest stable - Class: Enumerator::ArithmeticSequence

Method not available on this version

This method is only available on newer versions. The first available version (v2_6_3) is shown here.

each()
public

No documentation available.

static VALUE
arith_seq_each(VALUE self)
{
    VALUE c, e, s, len_1, last;
    int x;

    if (!rb_block_given_p()) return self;

    c = arith_seq_begin(self);
    e = arith_seq_end(self);
    s = arith_seq_step(self);
    x = arith_seq_exclude_end_p(self);

    if (!RB_TYPE_P(s, T_COMPLEX) && ruby_float_step(c, e, s, x, TRUE)) {
        return self;
    }

    if (NIL_P(e)) {
        while (1) {
            rb_yield(c);
            c = rb_int_plus(c, s);
        }

        return self;
    }

    if (rb_equal(s, INT2FIX(0))) {
        while (1) {
            rb_yield(c);
        }

        return self;
    }

    len_1 = rb_int_idiv(rb_int_minus(e, c), s);
    last = rb_int_plus(c, rb_int_mul(s, len_1));
    if (x && rb_equal(last, e)) {
        last = rb_int_minus(last, s);
    }

    if (rb_num_negative_int_p(s)) {
        while (NUM_GE(c, last)) {
            rb_yield(c);
            c = rb_int_plus(c, s);
        }
    }
    else {
        while (NUM_GE(last, c)) {
            rb_yield(c);
            c = rb_int_plus(c, s);
        }
    }

    return self;
}