From: Mike Nelson Date: 2006-05-22T06:54:15+09:00 Subject: Re: rubynuby - confused by method name "inject" Jim Weirich wrote: > How I remember: Inject takes a binary operation (e.g. +) and injects it > between each element of a list. > > [1,2,3].inject { |a,b| a+b } => 1+2+3 > > -- Jim Weirich I think about this in a slightly different way, which helps me rememeber. Something like, "#inject itorates over thie items in order but also _injects_ the result from the last block call into the current one." (1..5).inject { |injected_value, this_item| injected_value + this_item } => 15 -- Posted via http://www.ruby-forum.com/.