sort a hash with sort_by : sort_by « Hash « Ruby






sort a hash with sort_by


to_do = { 'Clean car' => 5, 'Take' => 3,
          'Real' => 3 }
to_do.sort_by { |task, priority| [priority, task] }.each { |k,v| puts k }

 

Related examples in the same category