Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ruby中对子数组进行排序_Ruby_Sorting - Fatal编程技术网

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

如何在ruby中对子数组进行排序,ruby,sorting,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>

我需要对以下内容进行分类,欢迎提出任何意见:

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"],
]
a=[
[“******************1*************,“20120210 08:04:05404调试MQReceiver-接收消息”“,”\n“],
[“******************3*************”,“20120210 08:04:00404调试MQReceiver-已发送消息”“,“\n”],
[“*********************2*************”,“20120210 08:03:05404调试MQReceiver-已分配消息”“,“\n”],
]

如何按时间或步骤1,2,3对该数组进行排序-通常的a.sort{x,y | xy}在这里不起作用

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

“按时间或按步骤”没有意义(考虑扩展解释和/或输入+结果)。此外,
sort{x,y{x y}
最好写成
sort
。但是,我想你想做一些事情,比如
sort{x,y{x[1]y[1]
或者使用
sort_by{e}/code>,等等--很好,成功了,其余的没有产生正确的结果
************************************1******************************20120210 08:04:05404调试MQReceiver-接收消息***************************************************************************2*********20120210 08:03:05404调试MQReceiver-分配的消息***************************************************************20120210:04:00404nks很多-我花了2个月的时间做了类似这样的事情