I have an array that I want to iterate over and delete some of the elements. This doesn\'t work:
a = [1, 2, 3, 4, 5] a.each do |x| next if x < 3 a.del
You don't have to delete from the array, you can filter it so:
a = [1, 2, 3, 4, 5] b = a.select {|x| x < 3} puts b.inspect # => [1,2] b.each {|i| puts i} # do something to each here