On Wed, Jun 22, 2011 at 11:50 AM, Iki Baz Castillo <ibc / aliax.net> wrote:
>
> Ok. I get some data and convert it into a Hash whose key is a priority
> value (integer, 0 is the best priority). The value of each entry is of
> course the data value associated with such priority. But such hash has
> not been ordered, this is, probably entry 1 has priority 2 while entre
> 2 has priority 1 (or whatever).
>
> Then I just want to get a new hash in which entries are ordered by
> priority.

I suspect you want to output this hash ordered by priority, correct?

Then why not leave the sorting and such to the emitter of the output?

Like so:

PRIORITIES = [0,1,2,3,4] # 5 priorities are enough for everyone ;)

items_to_do = {0 => 'Do it right now!', 4 => 'Sometime this decade', 1 => 'This
 can wait.'}

PRIORITIES.each do |prio|
  puts "#{prio}: #{items_to_do[prio]}" unless items_to_do[prio].nil? #
Suppress output of "empty" priorities
end

It's ordered output, and you don't have to sort the hash.

Mind, I'm curious about the why, and not saying you are wrong, or that
my way is better. :)

-- 
Phillip Gawlowski

A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
- Leibnitz