While below is perfect :

a = [
  {
    "id"=>1,
    "popularity"=>7.77030797174916,
    "title"=>"Another film",
  },
  {
    "id"=>2,
    "popularity"=>2.7703074916,
    "title"=>"A film",
  },
  {
    "id"=>3,
    "popularity"=>9.77030797174916,
    "title"=>"A third film",
  }
]
a.sort_by{|h| h["popularity"]}
# => [{"id"=>2, "popularity"=>2.7703074916, "title"=>"A film"},
#     {"id"=>1, "popularity"=>7.77030797174916, "title"=>"Another
film"},
#     {"id"=>3, "popularity"=>9.77030797174916, "title"=>"A third
film"}]


Not the below works as expected :

a = [
  {
    "id"=>1,
    "popularity"=>7.77030797174916,
    "title"=>"Another film",
  },
  {
    "id"=>2,
    "popularity"=>2.7703074916,
    "title"=>"A film",
  },
  {
    "id"=>3,
    "popularity"=>9.77030797174916,
    "title"=>"A third film",
  }
]
a.sort{|h| h["popularity"]}
# => [{"id"=>3, "popularity"=>9.77030797174916, "title"=>"A third
film"},
#     {"id"=>2, "popularity"=>2.7703074916, "title"=>"A film"},
#     {"id"=>1, "popularity"=>7.77030797174916, "title"=>"Another
film"}]

Why so? please help me...
Thanks

-- 
Posted via http://www.ruby-forum.com/.