From: x1 Date: 2005-12-24T08:25:48+09:00 Subject: How to sort this hash? Is it possible to sort the jobs hash below based on values such as command, start_time and stop_time? Ideally, sort_by would be dynamically provided and I would output the jobs entries based on the value defined for sort_by. --------------------------(basic_script.rb)------------------------ sort_by = "start_time" #<---- I'd like to use something like this to define which job is listed first jobs = { "2231" => {"command" => "test_a.bash", "start_time" => "20051211", "stop_time" => "20051222"}, "1131" => {"command" => "test_b.bash", "start_time" => "20051011", "stop_time" => "20051122"}, "231" => {"command" => "test_c.bash", "start_time" => "20051215", "stop_time" => "20051227"} } jobs.each do |job, attributes| puts "------------------" puts attributes["command"] puts attributes["start_time"] puts attributes["stop_time"] end --------------------------(/basic_script.rb)------------------------ This is the default output: ./basic_script.rb ------------------ test_c.bash 20051215 20051227 ------------------ test_b.bash 20051011 20051122 ------------------ test_a.bash 20051211 20051222 Id like to have the dynamics of say, ordering these by attribute such as start_time: (I wish I could get this) test_b.bash 20051011 20051122 ------------------ test_a.bash 20051211 20051222 ------------------ test_c.bash 20051215 20051227 Any suggestions? thanks in advance.