我有这样的样本数据:
[
[{"calendar"=>{:start_date=>Thu, 07 Aug 2014, :title=>"Recurring Event Test", :has_downloads=>false, :description=>"<p>Recurring content</p>\r\n", :location=>"Lunch hall", :id=>243, :end_date=>Thu, 07 Aug 2014}}],
[{"calendar"=>{:start_date=>Wed, 06 Aug 2014, :title=>"Single event", :has_downloads=>false, :description=>"<p>for date 6th</p>\r\n", :location=>"chennai", :id=>253, :end_date=>Wed, 06 Aug 2014}}]
]
需要start_date
字段排序此值。
我试过这个
sort_by {|vn| vn[:start_date]}
显示错误nil class
答案 0 :(得分:3)
vn
是一个数组,start_date
嵌套在calendar
内。你应该做
arr.sort_by {|vn| vn[0]["calendar"][:start_date]}