Refactoring

This uses Enumerable#min_by to find the right method in a nicer way.