From: Martin DeMello Date: 2003-08-31T05:23:31+09:00 Subject: Re: multiply all array with array Sabby and Tabby wrote: > > Should #mapwith work with 3 or more arrays like #zip does? > > p [1,2,3].mapwith([4,5,6], [7,8,9]) {|i,j,k| i*j+k} Right you are. I'll rework it in the a.m. - too sleepy right now :) > Allowing #zip to take a block has been discussed before. Here's yet > another implementation: > > class Array > alias _zip zip > def zip(*args) > if block_given? > _zip(*args).map {|a| yield a} > else > _zip(*args) > end > end > end > > p [1,2,3].zip([4,5,6], [7,8,9]) {|i,j,k| i*j+k} > > Unfortunately, it doesn't allow taking a symbol to an operator (:*) > like #mapwith does. The symbol was my main motivation for writing it, actually - map {|x,y| x*y} just felt redundant. martin