From: Siep Korteling Date: 2008-07-15T05:16:05+09:00 Subject: Re: how to loop through two arrays in parallel Glen Holcomb wrote: > On Mon, Jul 14, 2008 at 2:03 PM, Mitchell Gould > wrote: > >> Is there a way in Ruby to do this? >> >> >> for product in products[] and quantity in quantity[]? >> -- >> Posted via http://www.ruby-forum.com/. >> >> > product_quantity = {} > > products.each_with_index do |product, index| > product_quantity[product.to_sym] = quantity[index] > end > orderlist = products.zip(quantity) results in an array of arrays in stead of a hash. A hash is faster for lookup but looses the order (in Ruby 1.8.6), an array preserves the order. Hth, Siep -- Posted via http://www.ruby-forum.com/.