From: "Wayne E. Seguin" Date: 2007-07-10T21:41:23+09:00 Subject: Re: Beautiful Code : Pity he didn't ask here... --Apple-Mail-8--394346091 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jul 10, 2007, at 08:27 , Christoffer Sawicki wrote: > Hello. > > On 7/10/07, John Carter wrote: >> count.keys.sort_by{|key| count[key]} > > IMHO, the most elegant way to do this is: > > hash.sort_by { |k, v| v }.map { |k, v| k } > > ...where k = key and v = value. > > Cheers, Ack, pet peeve. hash.sort_by { | key, value | value } .map { | key, value | key } If you have to specify "where k = key and v = value" then these should have been used in your code. Always favor readability at the expense of verbosity, both your future self and whoever else maintains your code will thank you. -- Wayne E. Seguin Sr. Systems Architect & Systems Admin wayneseguin@gmail.com --Apple-Mail-8--394346091--