Method: Enumerable#each_with_object
- Defined in:
- enum.c
#each_with_object(obj) {|(*args), memo_obj| ... } ⇒ Object #each_with_object(obj) ⇒ Object
Iterates the given block for each element with an arbitrary object given, and returns the initially given object.
If no block is given, returns an enumerator.
evens = (1..10).each_with_object([]) { |i, a| a << i*2 }
#=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
1975 1976 1977 1978 1979 1980 1981 1982 1983 |
# File 'enum.c', line 1975
static VALUE
enum_each_with_object(VALUE obj, VALUE memo)
{
RETURN_SIZED_ENUMERATOR(obj, 1, &memo, enum_size);
rb_block_call(obj, id_each, 0, 0, each_with_object_i, memo);
return memo;
}
|