From: gga Date: 2007-02-24T03:20:09+09:00 Subject: Re: Ruby's "case" doesn't behave like a normal switch On 22 Feb., 22:54, Guillaume Nargeot wrote: > The problem with ruby is that you can't use a switch as it behaves with many > other languages like C, php, etc. > > For example, you want to convert the following peace of code to ruby: > > switch (x) { > case 1: > case 2: > # do something > break; > case 3: > # do some other thing > break; > default: > > } For completeness sake, you can also emulate C's lack of a break; statement in ruby by doing redo/retry, like: a = 1 catch(:redo) do case a when 1 print '1' a = 2 redo when 2 puts 'and 2' end end This makes ruby's case statement probably the best of any language.