If I iterate over a hash once, then do so again without modifying the contents, are the keys guaranteed to appear in the same order?
A quick test suggests as much:
> h = {'a' => 1, 'b' => 2, 'c' => 3}
> 100_000.times.map { h.to_s == h.to_s }.all?
=> true
Another question, if the above is allowed, can I iterate through it changing only values, without adding any new keys, and have the ordering of the keys be unchanged?
similar to this python question: Do dicts preserve iteration order if they are not modified?
Unlike the proposed duplicate I'm not interested in whether the elements have a fully specified order, only the restriction that two consecutive iterations without modification provide the same sequence.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…