Class | SyncEnumerator
In: | generator.rb
Parent: | Object

SyncEnumerator creates an Enumerable object from multiple Enumerable objects and enumerates them synchronously.

## Example

      require 'generator'

      s = SyncEnumerator.new([1,2,3], ['a', 'b', 'c'])

      # Yields [1, 'a'], [2, 'b'], and [3,'c']
      s.each { |row| puts row.join(', ') }

### Methods

each end? length new size

### Included Modules

Enumerable

### Public Class methods

new(*enums)

Creates a new SyncEnumerator which enumerates rows of given Enumerable objects.

[Source]

    # File generator.rb, line 186
      def initialize(*enums)
        @gens = enums.map { |e| Generator.new(e) }
      end

### Public Instance methods

each() {|ret| ...}

Enumerates rows of the Enumerable objects.

[Source]

    # File generator.rb, line 214
      def each
        @gens.each { |g| g.rewind }

        loop do
          count = 0

          ret = @gens.map { |g|
            if g.end?
              count += 1
              nil
            else
              g.next
            end
          }

          if count == @gens.size
            break
          end

          yield ret
        end

        self
      end

end?(i = nil)

Returns true if the given nth Enumerable object has reached the end. If no argument is given, returns true if any of the Enumerable objects has reached the end.

[Source]

    # File generator.rb, line 205
      def end?(i = nil)
        if i.nil?
          @gens.detect { |g| g.end? } ? true : false
        else
          @gens[i].end?
        end
      end

length()

Returns the number of enumerated Enumerable objects, i.e. the size of each row.

[Source]

    # File generator.rb, line 198
      def length
        @gens.length
      end

size()

Returns the number of enumerated Enumerable objects, i.e. the size of each row.

[Source]

    # File generator.rb, line 192
      def size
        @gens.size
      end

[Validate]