From: Chris Carter Date: 2007-03-26T08:30:42+09:00 Subject: Re: Backus, Functional Programming, and Ruby On 3/25/07, Jesse Merriman wrote: > On Sunday 25 March 2007 18:47, Devin Mullins wrote: > > module Enumerable > > def inner_product > > transpose.map(&:*).inject(&:+) > > end > > end > > That looks good, but is it right? > > irb(main):001:0> module Enumerable > irb(main):002:1> def inner_product > irb(main):003:2> transpose.map(&:*).inject(&:+) > irb(main):004:2> end > irb(main):005:1> end > => nil > irb(main):006:0> [[0,1,2], [6,5,4]].inner_product > TypeError: wrong argument type Symbol (expected Proc) > from (irb):3:in `inner_product' > from (irb):6 > > $ ruby --version > ruby 1.8.5 (2006-12-04 patchlevel 2) [i686-linux] > > -- > Jesse Merriman > jessemerriman@warpmail.net > http://www.jessemerriman.com/ > > He is assuming you have the famed "Symbol#to_proc" method, you can find it with a quick google. -- Chris Carter concentrationstudios.com brynmawrcs.com