In Ruby it is safe to add an element to the end of an array during iteration.

a = [0,1,2]
a.each do |b|
puts b
if 1 == (b % 2)
a << a.last + 1
end
end
Ranges as are not arrays.
a = (0..2)

By AJ ONeal

If you loved this and want more like it, sign up!


Did I make your day?
Buy me a coffeeBuy me a coffee  

(you can learn about the bigger picture I'm working towards on my patreon page )