Mark Hubbart
4/14/2005 9:05:00 PM
On 4/14/05, Martin DeMello <martindemello@yahoo.com> wrote:
> Mark Hubbart <discordantus@gmail.com> wrote:
> > If the result you want is:
> > (1..4).weave('a'..'d') #==>[1, "a", 2, "b", 3, "c", 4, "d"]
>
> But what about (1..10).weave('a'..'d')?
Empty spaces get filled with nils; elements beyond the number in the
receiver on enumerables passed as arguments will be ignored.
(1..10).weave('a'..'d') #==>[1, "a", 2, "b", 3, "c", 4, "d", 5, nil,
6, nil, 7, nil, 8, nil, 9, nil, 10, nil]
('a'..'d').weave(1..10) #==>["a", 1, "b", 2, "c", 3, "d", 4]
I glanced at the OP's code again, and I'm pretty sure that works the
same way, but in a faster and more generalized fashion.
cheers,
Mark