Ruby Language Existing methods


Example

If an iteration method such as each is called without a block, an Enumerator should be returned.

This can be done using the enum_for method:

def each
  return enum_for :each unless block_given?

  yield :x
  yield :y
  yield :z
end

This enables the programmer to compose Enumerable operations:

each.drop(2).map(&:upcase).first
# => :Z