(1..4).collect do |x| next if x == 3 x + 1 end # => [2, 3, nil, 5] # desired => [2, 3, 5]
If the condition for next is m
next
i would suggest to use:
(1..4).to_a.delete_if {|x| x == 3}
instead of the collect + next statement.