Patrick Hurley
3/22/2005 3:16:00 PM
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
<csaba@phony_for_avoiding_spam.org> wrote:
> On 2005-03-22, James Edward Gray II <james@grayproductions.net> 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
>
>