From: Robert Klemme Date: 2010-11-27T00:26:22+09:00 Subject: Re: Newbie: two cool discoveries On Fri, Nov 26, 2010 at 3:00 PM, Diego Virasoro wrote: > I find the case statement particularly elegant: especially when > there's a long list of choices I much prefer it to using if... > elsif... else... end. That said the latter offers a lot more > flexibility. I'm curios to hear whether you maintain that statement after seeing the other (apparently mostly unknown) variant of case: case # nothing here! when x > 1 puts "great" when sun.shines && temp > 20 puts "warm" when 3 == 9, 21 < 17 puts "weird" else puts "what?" end This is basically the same as an if-elsif-else-end cascade with a shorter syntax for "||" (i.e. the comma after "when"). Also, you can return values from case statements: puts case # nothing here! when x > 1 "great" when sun.shines && temp > 20 "warm" when 3 == 9, 21 < 17 "weird" else "what?" end Of course this can also be done with if-elsif-else-end. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/