summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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
commitd4d497dd86962d333337b70392623ccde5a053c2 (patch)
treea166b4c7589acc7adf69ab3b0e2a0acda5264182 /lib
parent44f0517a1381df95b8a8e852d273c2341f1c5917 (diff)
This commit was manufactured by cvs2svn to create branch 'ruby_1_8'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/rexml/syncenumerator.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/rexml/syncenumerator.rb b/lib/rexml/syncenumerator.rb
new file mode 100644
index 0000000000..955e006cb2
--- /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