Enumerator

Also, most iteration methods without a block returns an enumerator. For
example, Array#map returns an
enumerator if a block is not given. The enumerator has the #with_index method. So
ary.map.with_index works as follows.

Public Class Methods

new(obj, method = :each, *args)click to toggle source

new { |y| ... }

Creates a new Enumerator object, which is to
be used as an Enumerable object iterating in
a given way.

In the first form, a generated Enumerator
iterates over the given object using the given method with the given
arguments passed. Use of this form is discouraged. Use Kernel#enum_for(),
alias to_enum, instead.