From: Charles Oliver Nutter Date: 2009-02-15T07:06:54+09:00 Subject: Re: If you are unhappy with the direction of Ruby 1.8.7+, respond James Coglan wrote: > Regardless of whether they're *supposed* to, the Rubies I've used before > 1.8.7 actually do iterate in insertion order. Could be machine/OS specific, > a fluke, whatever. The point is that 1.8.7 definitely does not iterate in > the order that keys appear in a literal, at least on my machine. If this is > supposed to now be defined behaviour I'll investigate further and file a bug > if necessary. They only appeared to be ordered in the cases you saw, especially in cases of smaller hashes (fewer possible permutations of unordered). They never were actually ordered. This is the Truth. Naturally, unordered or "order unspecified" hashes may sometimes produce what seems to be ordered iteration. But it is entirely by chance. And this has come up countless times...someone will iterate their three-element hash and it will come out in insertion order. Then they'll expand to a larger hash or a different implementation and it stops being ordered. They cry foul, ruby-talk intervenes, and they learn hashes are not ordered in 1.8.6. I don't know what 1.8.7 does. 1.9.1 and JRuby (1.8.6 and 1.9.1 modes) both maintain hash keys in insertion order. Maintaining insertion order is simply a special case of unspecified ordering, so it's valid moving forward to *add* ordering, but not valid to take it away. - Charlie