Hash sort

S

Shandy Nantz

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
 
S

Shandy Nantz

Shandy said:
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]).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top