M
Martin Boese
Hello,
I am building a menu structure for rails that I'd like to store in a simple
Hash.
Now I found out that ruby Hashes do not keep the order, like this program:
...will output:
(vkvxxm and jmay are swapped)
I read an article describing this behavior, but it only mentions a 'sort'
solution which is useless for me because my menu has a logical order:
http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/159776
Are there any workarounds for this? Or shall I rather write my own containers?
BTW: Why is ruby doing this anyways...?!
Thanks,
Martin
I am building a menu structure for rails that I'd like to store in a simple
Hash.
Now I found out that ruby Hashes do not keep the order, like this program:
b = {'upkpgn'=>1,
'jmay'=>2,
'vkvxxm'=>3}
b.each_key {|k|
puts "%s => %s" % [k, b[k]]
}
...will output:
upkpgn => 1
vkvxxm => 3
jmay => 2
(vkvxxm and jmay are swapped)
I read an article describing this behavior, but it only mentions a 'sort'
solution which is useless for me because my menu has a logical order:
http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/159776
Are there any workarounds for this? Or shall I rather write my own containers?
BTW: Why is ruby doing this anyways...?!
Thanks,
Martin