Class | Enumerator
In: | lib/core/facets/enumerator.rb lib/core/facets/enumerator/fx.rb lib/core/facets/to_hash.rb
Parent: | Object

### Methods

fx new to_h to_h_assoc to_h_auto to_h_flat to_h_multi to_h_splat

### External Aliases

initialize | -> | old_initialize

### Public Class methods

new(*args, &block)

Provides the ruby-1.9 block form of Enumerator, where you can write:

       obj = Enumerator.new do |yielder|
         # ...
         yielder.yield(data)  # or: yielder << data
         # ...
       end

When obj.each is called, the block is run once. It should call yielder.yield with each item it wishes to generate.

Example:

      fib = Enumerator.new { |y|
        a = b = 1
        loop {
          y << a
          a, b = b, a + b
        }
      }

      fib.take(10)  #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

### Public Instance methods

fx()
to_h(mode=nil)

Convert an Enumerator object into a hash. This is equivalent to Array#to_h.

      e1 = [[1,:a],[2,:b],[3,:c]].to_enum
      e1.to_h #=> { 1=>:a, 2=>:b, 3=>:c }

      e2 = [1,2,3,4,5].to_enum
      e2.to_h  #=> {5=>nil, 1=>2, 3=>4}

      e3 = [1,2,1,3,1,5].to_enum
      e3.to_h #=> {1=>5}

CREDIT: Sandor Szücs

to_h_assoc()

This is equivalent to Array#to_h_assoc.

to_h_auto()

This is equivalent to Array#to_h_auto.

to_h_flat()

This is equivalent to Array#to_h_flat.

to_h_multi()

This is equivalent to Array#to_h_multi.

to_h_splat()

This is equivalent to Array#to_h_splat.

[Validate]