2

I recently saw this in the source code of one of the applications that I was working on and came to know that this is equivalent to:

some_array.each { |element| some_random_method(element) }

How does this work internally?

Anshul Mengi
  • 311
  • 1
  • 8

1 Answers1

2
               VALUE
rb_ary_each(VALUE array)
{
    long i;
    volatile VALUE ary = array;

    RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length);
    for (i=0; i<RARRAY_LEN(ary); i++) {
        rb_yield(RARRAY_AREF(ary, i));
    }
    return ary;
}

From Documentation.

Saurabh
  • 71,488
  • 40
  • 181
  • 244