From: William Crawford Date: 2006-09-13T00:17:47+09:00 Subject: Re: Maximum value of hash Bart Braem wrote: > A very simple question: what's the best way to get the maximum value of > a > hash? Currently I have something like: > > max = 0 > hash.each_value do |value| > if (value > max ) > max = value > end > end > > But it does not feel ruby... Same question for sum, but I guess the > answer > will be similar? > > Bart hash = Hash.new hash['a']=4 => 4 hash['b']=10 => 10 hash['c']=7 => 7 hash.max => ["c", 7] hash.values.max => 10 That? -- Posted via http://www.ruby-forum.com/.