Replace sort_by {...}.last with max_by

Enumerable#max_by was added in Ruby 1.8.7.  Switching from sort_by has
the advantage of not creating a garbage Array that is immediately thrown
away and is more intention-revealing.