I think I’ve found a gotcha. Really, it should be expected behavior, but
it wasn’t immediately obvious to me, so I thought it’s at least worth
Let’s say you want to iterate through an array and delete any items in
that array that match a certain criteria. I thought it’d make sense to
items.each do |x|
if x == “”
If items.each referred to items by reference, this would make sense.
But since it references by value, you’re literally changing the array
live, as you’re iterating through it. This means that, if you delete an
item in mid-iteration, you change the index of items. Since you
deleted something, you skip the next item.
Do I have this right?
Am I right in assuming that it’s possible to create an infinite loop
this way by continually push()ing things on to items?