From: Patrick Hurley Date: 2005-03-23T00:15:58+09:00 Subject: Re: stepping through arrays simultaneously I like transpose as well, but FYI there is also the generator library: require 'generator' a = [1, 2, 3] b = ['a', 'b', 'c'] c = [:a, :b, :c] gen = SyncEnumerator.new(a, b, c) gen.each {|x, y, z| puts "#{x} #{y} #{z}" Patrick On Tue, 22 Mar 2005 12:04:59 +0900, Csaba Henk wrote: > On 2005-03-22, James Edward Gray II wrote: > >> times = [ '1', '2', '3', '4', '5'] > >> events = [ 'eat', 'sleep', 'eat', 'play', 'sleep' ] > >> > >> times.size.times { |cnt| > >> puts times[cnt] + ": " + events[cnt] > >> } > > Sure is. You want Array#zip(). > > There is also Array#transpose: > > [times, events].transpose.each { |t,e| > puts t + ":" + e > } > > Or maybe: > > [times, events].transpose.each { |te| > puts te.join(":") > } > > Csaba > >