module Enumerable(T)


The Enumerable mixin provides collection classes with several traversal, searching, filtering and querying methods.

Including types must provide an each method, which yields successive members of the collection.

For example:

class Three
  include Enumerable(Int32)

  def each
    yield 1
    yield 2
    yield 3

three =
three.to_a                # => [1, 2, 3] &.odd?       # => [1, 3]
three.all? { |x| x < 10 } # => true

Note that most search and filter methods traverse an Enumerable eagerly, producing an Array as the result. For a lazy alternative refer to the Iterator and Iterable modules.

Direct including types

Defined in:


Instance Method Summary

Instance Method Detail

def parallel(*, fibers : Int32 = System.cpu_count.to_i) #

TODO better error handling * See Concurrent::Stream


[View source]