From: Steven Lumos Date: 2006-09-14T09:57:06+09:00 Subject: Re: Maximum value of hash "Marcelo Alvim" writes: >> Actually the Enumerable mixin module implements max, so any enumerable >> has it, and gives you the maximum element yielded by each >> >> (1..10).max #=> 10 >> {'a' => 1, 'b' => 7}.max #=> ["b", 7] >> "abc\ndef".max #=> "def" > > This is really sweet, but I think in this context it's worth noting that: > > {'a' => 1, 'b' => 10, 'z' => 5}.max #=> ["z", 5] > > As the thread is about hashes, it's nice to know that the #max method, > when applied to hashes, apparently yields the maximum value for the > keys, not for the values. > > Alvim. {'a' => 1, 'b' => 10, 'z' => 5}.max {|a,b| a[1] <=> b[1]} #=> ["b", 10] Steve