From: Just Another Victim of the Ambient Morality Date: 2006-08-22T11:50:09+09:00 Subject: Re: Why Does Hash Apparently Reorder Its Internal Representation And Other Associated Ponderings wrote in message news:2d4684b07b9f965e5078fdb46754fac3@shiny... > > 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?... How would this even work? For instance: hash = { 0 => 'a', 1 => 'b', 'c' => 'd' } # for me, this prints 'a', 'd', 'b', in that order... hash.each { |k,e| puts e } puts hash[1] # what will this print? There's no way to tell whether the last line of this code is trying to access the second element of the hash or the one that maps to the Fixnum 1...