From: Pit Capitain Date: 2002-03-14T16:06:48+09:00 Subject: Re: process two arrays pairwise? On 14 Mar 2002, at 4:23, Ron Jeffries wrote: > On Wed, 13 Mar 2002 16:55:45 GMT, Paul Brannan > wrote: > > >On Thu, Mar 14, 2002 at 01:00:01AM +0900, Ron Jeffries wrote: > >> Is there somewhere in Ruby a way to process the elements of two > >> arrays (of equal size), pairwise? > > > >There are a number of options. I'll let you dig through them: > > > >http://www.rubycentral.com/faq/rubyfaq-5.html#ss5.5 > >http://www.rubygarden.org/article.php?sid=107 > >http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/rubycollections/rubyco > >llections/rbc/iterator/ http://www.hduchene.de/ruby/index.html > > Hmm, well, those aren't it. Thanks! Maybe I like what I had best for > now: it has the virtue of simplicity. Don't know exactly what you didn't like about those, but just in case you're still willing to look for alternatives: there's generator.rb in http://www.ruby-lang.org/~knu/cgi-bin/cvsweb.cgi/rough/lib Your example array1.each_with_index { | a1, i | a2 = array2[i] # process a1, a2 } then becomes SyncEnumerator.new( array1, array2 ).each { | a1, a2 | # process a1, a2 } Regards, Pit