------art_131440_29734245.1161076983310
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 10/17/06, Peter Szinek <peter / rubyrailways.com> wrote:
>
> Hello,
>
> 1)
> I would like to create an array of n empty arrays, i.e.
>
> [ [], [], ... n-3 []'s, [] ]


Nicely answered

>
> 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] ]

I suppose you forgot the "," if you forgot the enclosing "[", "]" just
remove the splash operator (*) below:

some_func( *[*0..n-1].map{|line| [*n*line+1..n*line+n] } )

It is quit ugly maybe you should seek for less concentrated code though ;)
The parser is doing a great job here, I am really abusing it :(

HTH
Robert

Thanks,
> Peter
> http://www.rubyrailways.com
>
>
>


-- 
The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.

- George Bernhard Shaw

------art_131440_29734245.1161076983310--