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?
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?
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.