2009/2/12 James Coglan <jcoglan / googlemail.com>:
>>
>>
>>
>> What do you mean with "Hash ordering"?
>> An order for Hash instances? Hash doesn't define a <=> method.
>> Or iteration order of Hash elements? That wasn't defined
>> in 1.8.6 (I don't know if it is in 1.8.7).
>
>
>
> In 1.8.6, iteration order would be the same as the order that the keys
> appear in the source.

Iteration order is undefined, even for hash literals.
This is on *my* machine:

    $ ruby -v -e '{2 => 0, 1 => 0}.each_pair { |k,v| p k }'
    ruby 1.8.6 (2007-09-24 patchlevel 111) [x86_64-linux]
    1
    2

Your code happened to work by chance.

> To work with 1.8.7, you need to create an empty hash
> and add keys one by one rather than putting them all in a hash literal (see
> the patch).

Do I understand that the code relies on insertion order now?
Then it's still working by chance in case it works at all.

Stefan