# Sorting with Hash

**URL:** <https://www.ruby-forum.com/t/sorting-with-hash/58971>\
**Category:** Ruby\
**Created:** [April 27, 2006, 2:51pm UTC](https://www.ruby-forum.com/t/sorting-with-hash/58971 "2006-04-27T14:51:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![udinesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/a87d85/32.png) [@udinesh](https://www.ruby-forum.com/u/udinesh)\
**Post date:** [April 27, 2006, 2:51pm UTC](https://www.ruby-forum.com/t/sorting-with-hash/58971/1 "2006-04-27T14:51:21Z")

</div>

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
