From: "RadosÅ‚aw BuÅ‚at" Date: 2008-03-26T23:35:57+09:00 Subject: Re: The inject function > I want to add together numbers in an array with the inject command. I > want only the even numbers using only inject. > > So, something like [1,2,3,4].inject.....but don't know what to do so > help! puts [1, 2, 3, 4].inject(0) {|a, e| (e % 2 == 0) ? e + a : a } > Second, I need to reverse an array using only the inject command. So, > something like above with the result [4,3,2,1] Use .reverse method. inject doesn't fit in. -- Rados³aw Bu³at http://radarek.jogger.pl - mój blog