Ruby max\_by method finds the maximal element form an array. Sometimes the maximal elements are with multipicity, in this case max\_by chooses only one of them, seemingly arbitrarily. When I need all of them, I use this approach currently, to find the maximal values in an array of arrays:

```
sorted=ary.sort_by{|a,b| b}.reverse
max_score=sorted.first[1]
t=sorted.take_while{|z| z[1]==max_score}

```

But how could I monkey-patch the Array class with a "maxes\_by" method, which accept a block, similarly to max\_by, and returns an array of the maximal values?