From: diego scataglini Date: 2007-07-11T22:31:00+09:00 Subject: Re: Beautiful Code : Pity he didn't ask here... Nice, didn't know about it. Erlang has a similar thing for throwaway values. Thanks James Diego Scataglini On Jul 10, 2007, at 9:23 AM, James Edward Gray II wrote: > On Jul 10, 2007, at 8:13 AM, Gregory Brown wrote: > >> On 7/10/07, Wayne E. Seguin wrote: >>> 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. >> >> I find myself always using |k,v|, when used on something hashlike I >> don't think readability suffers. > > I've also recently adopted the trick of using _ as an unused > parameter name. I believe it was Ara that first suggested this and > I think it's a great idea: > > hash.sort_by { |key, _| … }… > > James Edward Gray II