From: "David A. Black" Date: 2008-12-01T04:29:44+09:00 Subject: Re: Help me understand how this block works? Hi -- On Mon, 1 Dec 2008, Brian A. wrote: > Thank you, that explains it very well for me. Another quick question. > Would it be possible to inject to two different vars? > > For instance if something like (syntax is probably wrong if its even > possible): > > (5..10).inject(1).inject(2) {|product, variable_two, n| product * > variable_two * n} If the collection you're iterating through has pairs of values, you can do this: [[1,2], [3,4], [5,6]].inject(0) {|acc, (x,y)| acc + x + y } Kind of pointless here, since I'm just adding them up, but that technique might help you. David -- Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS (Jan 12-15) | ADVANCING WITH RAILS (Jan 19-22) * Both in Fort Lauderdale, FL * Co-taught with Patrick Ewing See http://www.rubypal.com for details Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)