From: Robert Klemme Date: 2008-03-27T03:39:57+09:00 Subject: Re: The inject function On 26.03.2008 15:52, Eustáquio 'TaQ' Rangel wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > | I agree that reverse() is the correct tool for this job, but just to > | fully answer the question: > | >> [1, 2, 3, 4].inject([]) { |rev, item| [item] + rev } > > Just to use the same approach but with insert: > > |> [1,2,3,4,5,6].inject([]){|m,v| m.insert(0,v)} > => [6, 5, 4, 3, 2, 1] While we're improving... irb(main):001:0> [1,2,3,4,5,6].inject([]) {|a,x| a.unshift x} => [6, 5, 4, 3, 2, 1] Oh, I just see Dan has it already. Kind regards robert