diff options
| author | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 03:51:53 +0000 |
|---|---|---|
| committer | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-05-19 03:51:53 +0000 |
| commit | fa8573da6ad626b7b368362ee15972bdb17e75ca (patch) | |
| tree | a166b4c7589acc7adf69ab3b0e2a0acda5264182 | |
| parent | c9c9641b4dc399ded5e0e71b3a7201fb5e7e6181 (diff) | |
| download | ruby-fa8573da6ad626b7b368362ee15972bdb17e75ca.tar.gz ruby-fa8573da6ad626b7b368362ee15972bdb17e75ca.tar.xz ruby-fa8573da6ad626b7b368362ee15972bdb17e75ca.zip | |
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@8485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | lib/rexml/syncenumerator.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/rexml/syncenumerator.rb b/lib/rexml/syncenumerator.rb new file mode 100644 index 000000000..955e006cb --- /dev/null +++ b/lib/rexml/syncenumerator.rb @@ -0,0 +1,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 |
