summaryrefslogtreecommitdiff
path: root/jni/ruby/lib/rexml/syncenumerator.rb
blob: 11609bdf3daa9f16364daaa9a64ba7d4b6f1e947 (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
module REXML
  class SyncEnumerator
    include Enumerable

    # Creates a new SyncEnumerator which enumerates rows of given
    # Enumerable objects.
    def initialize(*enums)
      @gens = enums
      @length = @gens.collect {|x| x.size }.max
    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
      @length.times {|i|
        yield @gens.collect {|x| x[i]}
      }
      self
    end
  end
end