Ruby Max Method

Tonja Daniels
TonjaGraphix
Published in
1 min readMay 27, 2018

Today I learned how to do the “.max_by” method in Ruby. What this does is that it takes a countable collection and returns the item that qualifies as the maximum. See the example:

The .max_by method, is that it is a really efficient way to do complex comparisons. It stores the value that is returned in each block for each item and then it sorts on those return values directly.

As you can see Ruby’s “.max_by” is a simple way to do a complex algorithm! Until next time!

--

--