Forum: Ruby Sorting with Hash

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dinesh U. (Guest)
on 2006-04-27 16:51
Hi all,

I have a hash like this and i want to sort. After sorting i want the key
and value seperately. like say

c=Hash.new
h = { "c" => 20, "b" => 30, "a" => 10  }

c = h.sort
puts c
====>which will result in
a
10
b
30
c
20

puts c[0]
===>which will result in
a
10

Now after we have sorted i want to fetch the individual key/value like
we know 'a' is the key and 10 is the value above. How can we get them
individually (key/value after we sort)  any methods are there ? pl help
me out..

We are storing the sorted result in another hash c.

Can we get the individual key/value pairs from this c. (which is sorted)
??

Or is there any other other way to do ?

Thank You.
Dinesh
This topic is locked and can not be replied to.