From: 7stud -- Date: 2012-10-21T01:23:01+09:00 Subject: Re: Hash with Integer key issue unknown wrote in post #1080532: > Am 20.10.2012 14:46, schrieb Wayne Simmerson: >> Thanks for all the replies, I actually figured it out about 2 minutes >> after I posted the question. I was banging my head against my desk for >> hours trying to figure out why it wasn't working, completely oblivious >> to the fact it had been converted to an Array. It took writing it out >> here to notice the Hash had been Arrayed! >> >> Is there no way to sort the hash and convert it back in the same >> statement? Would be nice to do in a single line of code. > > Arlen already told you! > > new_hash = Hash[x.sort_by {|k,v| v }.reverse] > > But I do not see the use case for a sorted hash, > it appears conceptually wrong to me. Have you read Jan's post? > If you believe Hashes are unsorted, then why would you reverse an array before converting it to a Hash? -- Posted via http://www.ruby-forum.com/.