On Sun, Sep 18, 2011 at 12:30 PM, Robert Klemme
<shortcutter / googlemail.com> 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]