From: lasitha Date: 2009-03-26T02:19:24+09:00 Subject: Re: delete from array while iterating On Wed, Mar 25, 2009 at 10:30 PM, RubyTalk@gmail.com wrote: > [2,3,4,5,6].delete_if{|x| (x%2==0) && (puts x) } > 2 > 4 > 6 Err, that won't work. puts returns nil so the block will never return true and none of the items will be removed. We'd have to do: arr.delete_if do |e| if e.matches(condition) puts e true end end Note: this can work w/o an else because the whole if expression will return nil if none of the conditions match. cheers, lasitha