From: "David A. Black" Date: 2009-07-22T04:26:05+09:00 Subject: Re: Mean method --1926193751-650525245-1248204323=:17777 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-650525245-1248204323=:17777" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-650525245-1248204323=:17777 Content-Type: TEXT/PLAIN; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT Hi -- On Wed, 22 Jul 2009, Brian Candler wrote: > Älphä Blüë wrote: >> From my understanding of inject, using above.. >> >> a = first instance of array >> b = subsequent instances of array > > No, not exactly. You are using the new 1.9 usage (possibly also 1.8.7): > > foo.inject { |a,b| ... } > > a is the first element of the array in the first iteration only. For > subsequent iterations, a is the value of the previous block evaluation. > > It may be clearer if you stick to the old usage: > > foo.inject(init) { |a,b| ... } You can do the no-arg version in 1.8.6 too: $ ruby186 -e 'p [1,2,3].inject {|a,b| a + b }' 6 David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Now available: The Well-Grounded Rubyist (http://manning.com/black2) Training! Intro to Ruby, with Black & Kastner, September 14-17 (More info: http://rubyurl.com/vmzN) --1926193751-650525245-1248204323=:17777-- --1926193751-650525245-1248204323=:17777--