From: Gordon Thiesfeld Date: 2007-09-08T03:15:05+09:00 Subject: Re: array handling advice On 9/7/07, Chris McMahon 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