From: tsuraan Date: 2005-03-23T02:50:32+09:00 Subject: Re: stepping through arrays simultaneously On Mar 21, 2005, at 10:04 PM, 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(":") > } Starting to remind me of Matlab :) Is transpose a terribly expensive operation, compared with zip? Maybe rdoc should list big-O expense for operations or something. --jay