From: dblack@... Date: 2007-08-03T01:58:28+09:00 Subject: Re: sytnax Hi -- On Thu, 2 Aug 2007, Shai Rosenfeld wrote: > Phlip wrote: >> Shai Rosenfeld wrote: >> >>> ..quick reply (didn't last a minute) >>> :) >>> >>> thanks. >> >> Or... >> >> var = { 1 => 'one', 2 => 'two', 3 => 'three' }.fetch(number, 'else') > > nice! :) > > any lead to which one is faster? Some quick benchmarking suggests that for small numbers of items they're about equal, but the case one slows down faster as the number of choices increases, presumably because it has to do a comparison for each one instead of just one hash fetch. It would also depend on which one matched, though -- for example: case 1 when 1 then "one" when 2 then "two" ... when 1000000 then "one million" end will match on the first comparison, so it doesn't matter that there are a million of them. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)