From fa8573da6ad626b7b368362ee15972bdb17e75ca Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Thu, 19 May 2005 03:51:53 +0000 Subject: 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 --- lib/rexml/syncenumerator.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/rexml/syncenumerator.rb 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 -- cgit