I was surprised to find the following...
irb(main):001:0> {:a => 'a', :b => 'b'}
=> {:a=>"a", :b=>"b"}
irb(main):002:0> {:a => 'a', :b => 'b', :c => 'c'}
=> {:a=>"a", :b=>"b", :c=>"c"}
irb(main):003:0> {:a => 'a', :b => 'b', :c => 'c', :d => 'd'}
=> {:a=>"a", :d=>"d", :b=>"b", :c=>"c"}
irb(main):004:0> {:a => 'a', :b => 'b', :c => 'c', :d => 'd', :e => 'e'}
=> {:a=>"a", :d=>"d", :b=>"b", :e=>"e", :c=>"c"}
irb(main):005:0> {:a => 'a', :b => 'b', :c => 'c', :d => 'd', :e => 'e', :f => 'f'}
=> {:a=>"a", :d=>"d", :b=>"b", :e=>"e", :c=>"c", :f=>"f"}
I expected that the sequence of hashes returned would be identical in order to the presented sequence. Or, that there would be some discernable sequence such as if a stack, if not as a queue.
I realise that it is a hash and that access is expected to be by key, but sometimes retaining the presented order may be desired. And anyway, why reorder it at all?
Furthermore, the returned order is different from a previous sequence I did! So, it appears that this is somewhat random, however unlikely that it is.
I then assumed that there might be some kind of optimisation going on, but how much optimisation of {:a => 'a', :b => 'b', ... } can there be?
It doesn't seem very PoLS to have it reordered, although perhaps one shouldn't be surprised that a hash is unordered? Perhaps Matz is convincing us of this statement? Said Matz unto the flock in a loud, Godly voice: "Make no assumptions about the order of hashes!"
And would eval %{ instance_of_hash[instance_of_fixnum] } really be so evil? Perhaps that was a little obscure... What's wrong with ordered access, using a numeric element reference as with Array, to Hash? Excepting that the order can't be relied upon, but assume that it could. Even simpler might have been to give an example:
h = {:a => 'a', :b => 'b'}
h[0]
=> 'a'
Similarly one might be able to treat an Array like a Hash as in eval %{ instance_of_array['instance_of_string_representation_of_a_fixnum'] }, such as with:
a = [ 1, 2 ]
a['0']
=> 1
There's no great call for the immediately above I would think, but if I implemented one then I would implement the other also, simply for the purposes of symmetry. I'm not even sure there is any need for either, such that I may be trying to achieve the unnecessary?...
Even so, would some unwritten law be being broken if I did this stuff?