排序AWS3对象数组

时间:2014-01-31 08:36:33

标签: ruby-on-rails ruby amazon-s3

我有一组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>
        ] 

我需要根据特定文件的上次修改时间对数组进行排序。

2 个答案:

答案 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)