Module: Enumerable

Defined in:
runtime/ext/enumerable.rb,
runtime/ext/enumerable.rbs

Overview

Enumerable — the collection predicates and projections.

Instance Method Summary collapse

  • #index_by ⇒ Hash

    the collection as a Hash keyed by the block's value; last write wins on duplicates.

  • #many? ⇒ Boolean

    more than one element.

  • #sole ⇒ untyped

    the one element, asserting the count instead of only reading the first: first would keep the read and drop the assertion.

Instance Method Details

#index_by ⇒ Hash

the collection as a Hash keyed by the block's value; last write wins on duplicates.

Returns:

  • (Hash) —

    this collection keyed by the block's value



7
# File 'runtime/ext/enumerable.rb', line 7

def index_by: () { (untyped) -> untyped } -> Hash[untyped, untyped]

#many? ⇒ Boolean

more than one element.

length answers it because everything that reaches here is already materialized.

Returns:

  • (Boolean) —

    true when the collection holds two or more elements



19
# File 'runtime/ext/enumerable.rb', line 19

def many?: () -> bool

#sole ⇒ untyped

the one element, asserting the count instead of only reading the first: first would keep the read and drop the assertion.

Returns:

  • (untyped) —

    the collection's single element

Raises:

  • (RuntimeError) —

    the collection is empty or holds more than one element



28
# File 'runtime/ext/enumerable.rb', line 28

def sole: () -> untyped