From: Robert Klemme Date: 2012-08-16T23:43:48+09:00 Subject: Re: case vs if-else On Thu, Aug 16, 2012 at 4:23 PM, ajay paswan wrote: > Robert Klemme wrote in post #1072532: >> On Thu, Aug 16, 2012 at 1:43 PM, ajay paswan >> wrote: >>> Which one is faster? >> >> Measure it. There is Benchmark. >> > means? what measure? and who'll measure? You want to know which one is faster so you'll measure it. require 'benchmark' Benchmark.bm do |b| ... end http://www.ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/index.html >> SMARTNESS = { >> "A" => "you are smart", >> "B" => "you are dumb", >> } > is it mapping? looks like one. It's a Hash stored in a constant. A hash lookup is typically quite fast compared to control flow - especially if you increase the number of alternatives. But: measure it! >> puts SMARTNESS[grade] >> >> Cheers >> >> robert > > Whats that What? That's my name. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/