You asked why, so I'm going to break this down step by step, first we know map returns an array of values (same as FORMATS.values)
FORMATS.map {|_,v| v}
=> [
["vertical", "small", "small", "small", "small"],
["horizontal", "small", "small", "small", "small"],
["large", "small", "small"],
["vertical", "horizontal", "small", "small"],
["horizontal", "small", "small", "horizontal", "small", "small", "small"]
]
We then call Array#max without any arguments or a block which according to the docs:
Returns the object in ary with the maximum value. The first form assumes all objects implement Comparable;
In your case, each element is an array and since array does respond to the comparable operator <=>
it runs each element against each other like this:
FORMATS.map {|_,v| v}.max { |a, b| a <=> b }
However Array#<=> does it's own comparison element by element:
Arrays are compared in an “element-wise” manner; the first element of ary is compared with the first one of other_ary using the <=> operator, then each of the second elements, etc… As soon as the result of any such comparison is non zero (i.e. the two corresponding elements are not equal), that result is returned for the whole array comparison.
However when we call max we get back the first item in the array, why?
FORMATS.map {|_,v| v}.max
=> ["vertical", "small", "small", "small", "small"]
That's because if we look at this element-by-element, the first value is "vertical" and "vertical" is >= every first element for the other arrays which then leaves us only with the first element:
["vertical", "small", "small", "small", "small"]
and the 4th element
["vertical", "horizontal", "small", "small"]
If we then compare the second elements, small is > horizontal and we're done, the first element is the max.
You then call size on the max element which is 5.