From: Matthias Reitinger Date: 2008-07-08T19:52:36+09:00 Subject: Re: Multiply elements in array Axel Etzold wrote: > arr = ["abc", ["def", "def", "def"]] > arr_final=[] > arr[1].collect{|x| arr_final<<[arr[0],x]} > p arr_final You could also shorten the processing step a bit: arr_final = arr[1].collect { |x| [arr[0], x] } A little bit closer to what Chris had in mind would be: arr[0] = [arr[0]] * arr[1].size arr_final = arr.transpose Alternatively and without changing the original array: arr_final = ([arr[0]] * arr[1].size).zip(arr[1]) Yet another way to do this is available in Ruby 1.8.7/1.9 (I think): arr_final = [[arr[0]].product(arr[1]) HTH, Matthias. -- Posted via http://www.ruby-forum.com/.