Reputation: 13
a = [{"name"=> "ted","age"=>1},
{"name"=> "mika","age"=>2},
{"name"=> "bob","age"=>0}]
How do I can sort the a is an array in age order (ascending order) with ruby program?
I would like to be the following.
a = [{"name"=> "bob","age"=>0},
{"name"=> "ted","age"=>1},
{"name"=> "mika","age"=>2}]
Upvotes: 0
Views: 53
Reputation: 13
As Cary Swoveland told in comment,
a.sort_by { |h| h["age"] }
I could do as above.thanks.
Upvotes: 1