[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Conditional inserts in inject

Weirich, James

9/8/2003 8:05:00 PM

> %w{ one two three }.inject(Array.new) { |a, e| if e !=
> "three" then a <<
> e else a end }

Since << is a modifying operation, the following also works ...

%w{ one two three }.inject(Array.new) { |a, e| a << e if e != "three"; a }

--
-- Jim Weirich / Compuware
-- FWP Capture Services
-- Phone: 859-386-8855