D
dc
hi -
sure this is a common question...
i have a hash of stuff that i want to load/keep in a particular order.
irb(main):005:0> hsh = { "one" => 1, "two" => 2, "three" => 3,
"four"=>4, "twentythree"=>23 }
gives back:
=> {"three"=>3, "two"=>2, "twentythree"=>23, "one"=>1, "four"=>4}
ruby sorts the hash in apparent random order (by object id?)
how can i keep the items in the order i want?
someone said i should probly not use a hash at all? however, i do want
to keep the items organized in the order like above, but access thru
hashkeys.
hsh.each_pair{ |tag, val| ...
can i use a more complex structure and sort by some internal key?
thanks!
/dc
sure this is a common question...
i have a hash of stuff that i want to load/keep in a particular order.
irb(main):005:0> hsh = { "one" => 1, "two" => 2, "three" => 3,
"four"=>4, "twentythree"=>23 }
gives back:
=> {"three"=>3, "two"=>2, "twentythree"=>23, "one"=>1, "four"=>4}
ruby sorts the hash in apparent random order (by object id?)
how can i keep the items in the order i want?
someone said i should probly not use a hash at all? however, i do want
to keep the items organized in the order like above, but access thru
hashkeys.
hsh.each_pair{ |tag, val| ...
can i use a more complex structure and sort by some internal key?
thanks!
/dc