我有一组aws对象。我想根据上次修改时间对对象进行排序。请参阅以下代码段
array = [<AWS::S3::S3Object:dt_publisher_reports/temp/2013.csv>,
<AWS::S3::S3Object:dt_publisher_reports/temp/2013_October.csv>,
<AWS::S3::S3Object:dt_publisher_reports/temp/2013_September_176.csv>,
<AWS::S3::S3Object:dt_publisher_reports/temp/2013_September_1764.csv>
]
我需要根据特定文件的上次修改时间对数组进行排序。
答案 0 :(得分:2)
试试这个
array = [<AWS::S3::S3Object:dt_publisher_reports/temp/2013.csv>,
<AWS::S3::S3Object:dt_publisher_reports/temp/2013_October.csv>,
<AWS::S3::S3Object:dt_publisher_reports/temp/2013_September_176.csv>,
<AWS::S3::S3Object:dt_publisher_reports/temp/2013_September_1764.csv>]
array.sort_by &:last_modified
答案 1 :(得分:0)
使用此
array.sort_by &:updated_at
或
array.order(:updated_at)