如何在ruby中对子数组进行排序

时间:2012-04-03 22:46:17

标签: ruby sorting

我需要对以下内容进行排序,任何想法都值得赞赏:

a=[
    ["****************1************","20120210 08:04:05,404 DEBUG MQReceiver - Receive message "<FIXML>","\n"],
    ["****************3************","20120210 08:04:00,404 DEBUG MQReceiver - Sent message "<FIXML>","\n"],
    ["****************2************","20120210 08:03:05,404 DEBUG MQReceiver - Allocated message "<FIXML>","\n"],
]

如何按时间或步骤1,2,3-通常的a.sort {| x,y |来排序此数组x&lt; =&gt; y}不在这里工作

1 个答案:

答案 0 :(得分:2)

如果您尝试按两个条件排序,请执行

a.sort_by do |item|
  time = parse_time_from_string(item[1])
  step = parse_step_from_string(item[0])
  [time, step]
end