Is the .each iterator in ruby guaranteed to give the same order on the same elements every time?

Viewed 5754

I'm doing something like this with a list 'a':

a.each_with_index |outer, i|
  a.each_with_index |inner, j|
    if(j > i)
      # do some operation with outer and inner
    end
  end
end

if the iterator is not going to use the same order, this won't work. I don't care what the order actually is, I just need for two .each_with_index iterators to use the same order.

I would assume that it would be a property of an array that it has a fixed order and I'm just being paranoid that the iterator wouldn't use that order...

4 Answers
Related