On 9/7/07, Chris McMahon <christopher.mcmahon / gmail.com> wrote:
>
> There is probably a simple way to do this, but I'm drawing a blank:
>
> I have an arbitrarily large input array, like
>
> input = ['a','b','c','d','e','f','g']
>
> and three target arrays like
>
> targ_one = []
> targ_two = []
> targ_three = []
>
> I want to deal out the elements of this array into three target arrays
> so they end up like
>
> ['a','d','g']
> ['b','e']
> ['c','f']
>

This is the best I could come up with:

require 'enumerator'

input = ['a','b','c','d','e','f','g']
input = *input.enum_slice(3)
targ_one, targ_two, targ_three = input.shift.zip(*input).map{|i| i.compact }

hth

Gordon