From: Adam Prescott Date: 2011-09-18T21:05:54+09:00 Subject: Re: array.map! + delete_if possible ? On Sun, Sep 18, 2011 at 12:30 PM, Robert Klemme wrote: > irb(main):010:0> a = 10.times.to_a > => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > irb(main):011:0> a.map! {|i| i.odd? ? i : nil}.compact! > => [1, 3, 5, 7, 9] > irb(main):012:0> a > => [1, 3, 5, 7, 9] A bit simpler: >> a = (1..10).to_a # don't really need the to_a for this, but hey => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >> a.select! { |e| e.odd? } => [1, 3, 5, 7, 9] >> a => [1, 3, 5, 7, 9]