From: Peter Szinek Date: 2006-10-17T18:20:45+09:00 Subject: Re: Array.new question > a = (0..3).collect{[]} # => [[], [], [], []] > a[0][0] = 1 > a # => [[1], [], [], []] Thx! >> 2) Is there an idiomatic way to do this (in a generic way, of course): >> >> some_func( >> [1,2,3] >> [4,5,6] >> [7,8,9] ) >> >> => [ [1,4,7], [2,5,8], [3,6,9] ] > [1,2,3].zip([4,5,6],[7,8,9]) # => [[1,4,7], [2,5,8], [3,6,9]] Sorry, I did not describe the scenario properly. The thing is that I am iterating over an array (of arrays) and I don't have the all the arrays at once (the inner arrays are generated on the fly). Let me illustrate it: input = [ [1,2,3], [4,5,6], [7,8,9] ] result = [] input.each { |i| do_something_with(result, i) } and the result should be [ [1,4,7], [2,5,8], [3,6,9] ] The question sounds: how is do_something_with implemented? I have already implemented it but I don't think so it's a state-of-the art solution ;) Thanks, Peter http://www.rubyrailways.com