# Hash sort

**URL:** <https://www.ruby-forum.com/t/hash-sort/163473>\
**Category:** Ruby\
**Created:** [March 20, 2009, 6:36pm UTC](https://www.ruby-forum.com/t/hash-sort/163473 "2009-03-20T18:36:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [March 20, 2009, 6:36pm UTC](https://www.ruby-forum.com/t/hash-sort/163473/1 "2009-03-20T18:36:02Z")

</div>

I am trying to sort a hash and it seams to be working, the issue is that  
the sort goes from Z-A. Is there a way to make it sort A-Z? My code is  
pretty straight foward, I have a hash - @users - and I just say  
@hash.sort to sort it.

Thanks,

-S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [March 20, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/hash-sort/163473/2 "2009-03-20T21:50:06Z")

</div>

Shandy N. wrote:

> I am trying to sort a hash and it seams to be working, the issue is that  
> the sort goes from Z-A. Is there a way to make it sort A-Z? My code is  
> pretty straight foward, I have a hash - @users - and I just say  
> @hash.sort to sort it.
> 
> Thanks,
> 
> -S

Figured it out. Part of my issue was that the key - which are string -  
that I was trying to sort were in upper and lowercase, once I converted  
them to lower case everything was fine. Here is the code I used:

@users.sort.each { |f| puts “#{f[0]} : #{f[1]}” }

This will print out the key (in f[0]) and the value (in f[1]).
