From: Brian Candler Date: 2007-02-24T00:25:53+09:00 Subject: Re: Ruby's "case" doesn't behave like a normal switch On Fri, Feb 23, 2007 at 10:18:34PM +0900, Olivier Renaud wrote: > Le vendredi 23 f�vrier 2007 11:30, Brian Candler a �crit�: > > On Fri, Feb 23, 2007 at 02:05:10PM +0900, Guillaume Nargeot wrote: > > > > case x > > > > when "this", "that" > > > > func_this_that() > > > > when "nothing" > > > > # something different > > > > end > > > > > > Thank you very much !!! > > > I thought I tested everything, but obviously not this one. > > > I didn't even find anything about it in the official documentation. > > > > http://www.rubycentral.com/book/tut_expressions.html > > Search down to the section headed "Case Expressions" > > I didn't know about this syntax, either. Thanks, Eban ! For the Strings, I > thought about using Regex, instead : > > case x > when /this|that/ > func_this_that() > when "nothing" > # something different > end That's not the same though. I think you'd need: when /\A(this|that)\z/ (which is a gotcha if you come from Perl, and expect to use ^...$ to match the start and end of the string) Regards, Brian.