Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Hash sort
Shandy Nantz
3/20/2009 5:33:00 PM
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
--
Posted via
http://www.ruby-...
.
1 Answer
Shandy Nantz
3/20/2009 8:47:00 PM
0
Shandy Nantz 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]).
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Hash sort
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password