summaryrefslogtreecommitdiff
path: root/lib/rexml/syncenumerator.rb
blob: 955e006cb2215503f430d537078463e65527ffbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module REXML
  class SyncEnumerator
    include Enumerable

    # Creates a new SyncEnumerator which enumerates rows of given
    # Enumerable objects.
    def initialize(*enums)
      @gens = enums
      @biggest = @gens[0]
      @gens.each {|x| @biggest = x if x.size > @biggest.size }
    end

    # Returns the number of enumerated Enumerable objects, i.e. the size
    # of each row.
    def size
      @gens.size
    end

    # Returns the number of enumerated Enumerable objects, i.e. the size
    # of each row.
    def length
      @gens.length
    end

    # Enumerates rows of the Enumerable objects.
    def each
      @biggest.zip( *@gens ) {|a|
        yield(*a[1..-1])
      }
      self
    end
  end
end