Flowdock
method

each

Importance_0
v2_6_3 - Show latest stable - 0 notes - Class: ArithmeticSequence
  • 1_8_6_287
  • 1_8_7_72
  • 1_8_7_330
  • 1_9_1_378
  • 1_9_2_180
  • 1_9_3_125
  • 1_9_3_392
  • 2_1_10
  • 2_2_9
  • 2_4_6
  • 2_5_5
  • 2_6_3 (0)
  • What's this?
each() public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
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;
}
Register or log in to add new notes.