From: Drew Olson Date: 2007-07-20T02:19:29+09:00 Subject: Re: Map more than one array at once Wil wrote: > Hi all, > > I've been using Ruby for a while now, and have enjoyed it immensely. > However, I haven't yet found how to map more than one array at once. > The common example is calculating the dot product. Here's an example using inject, no need for a temp variable: irb(main):001:0> def dot_prod a,b irb(main):002:1> a.zip(b).inject(0) do |dp,(a,b)| irb(main):003:2* dp + a*b irb(main):004:2> end irb(main):005:1> end => nil irb(main):006:0> dot_prod([1,2,3],[4,5,6]) => 32 -- Posted via http://www.ruby-forum.com/.