From: Martin DeMello Date: 2005-04-14T13:59:37+09:00 Subject: Re: Weaving Arrays galizur@gmail.com wrote: > > Any suggestions on a quick way to weave two arrays? This works as long as you pass it an array: class Array def weave(other) zip(other * (length / other.length + 1)).flatten end end Not very efficient, since it creates two intermediate arrays, but this is seldom a problem in practice. Here's a more efficient way: class Array def weave(other) l = other.length retval = [] each_with_index {|e,i| if block_given? yield [e, other[i%l]] else retval << e retval << other[i%l] end } return block_given? ? self : retval end end martin ~