From: dblack@... Date: 2006-05-22T20:39:37+09:00 Subject: Re: rubynuby - confused by method name "inject" Hi -- On Mon, 22 May 2006, Regg Mr wrote: > Leslie Viljoen wrote: >> On 5/21/06, Jim Weirich wrote: >>> Jeff Pritchard wrote: >>>> As for Inject, nobody has come up with a wording that makes any sense to >>>> me yet. Does Inject have any aliases/synonyms? >>> >>> 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 >> >> Awesome! That really helps me! > > > Seems like "sum" would have been a better name. Only in the case where you're calculating a sum :-) Inject does the sum-like thing but in a generalized way. David -- David A. Black (dblack@wobblini.net) * Ruby Power and Light, LLC (http://www.rubypowerandlight.com) > Ruby and Rails consultancy and training * Author of "Ruby for Rails" from Manning Publications! > http://www.manning.com/black