I want to sort an array of hashes in which each hash has two attributes created_time
and updated_time
. And the value of these attributes may be either a datestring or nil. I want it to sort by created_time(ASC) first and updated_time(ASC).I tried with sort_by method and I could not specify the condition for multiple keys like sort method suggested in this discussion .
The two attributes created_time and updated_time should be sorted in ascending order with null values as last
Suppose if the array is
[
{"created_time" => nil, "updated_time" => "2016-04-10"},
{"created_time" => nil, "updated_time" => "2016-04-09"},
{"created_time" => "2016-04-15", "updated_time" => nil}
]
I want the result as
[
{"created_time"=>"2016-04-15", "updated_time"=>nil},
{"created_time"=>nil, "updated_time"=>"2016-04-09"},
{"created_time"=>nil, "updated_time"=>"2016-04-10"}
]
What to do?