From: Gregory Brown Date: 2007-01-17T05:36:01+09:00 Subject: Re: Can anyone try to solve this problems? On 1/16/07, Sam Smoot wrote: > Here's my try at a Ruby 1.8 implementation of the Enumerable#max_by: > > > a = %w{ one two three four } > > > def a.max_by > > pairs = inject({}) do |hash, obj| > > hash[yield obj] = obj; hash > > end > > pairs[pairs.keys.max] > > end Yep, this is smarter than my ruby attempt :) Avoid the dependency on facets, Symbol#to_proc is the easiest thing in the world to write class Symbol def to_proc lambda { |x| x.send(self) } end end