Re: Sorting with Hash


#1

Sorry, after reading your post again I guess I haven’t
understand your problem.

Standard Hashes are not sorted, never. If you call
sort on a Hash you get nested arrays.

[[“a”, 10], [“b”, 30], [“c”, 20]]

if you want to iterate over this array just use each.

c.each{|k, v| do_something(k, v)}

if you want the value corresponding to a key use assoc.

c.assoc(‘b’) #=> 30

(but this is slow on large arrays)

Hth

Simon