From: Robert Dober Date: 2008-04-19T05:32:23+09:00 Subject: Re: How to "break" a "case-when" ? On Thu, Apr 17, 2008 at 4:14 PM, Robert Klemme wrote: > 2008/4/17, Stefan Lang : > > 2008/4/17, Iņaki Baz Castillo : > > > > > 2008/4/17, Stefan Lang : > > > > Well, since Ruby doesn't support it, you must find other > > ways to structure the code in each case. Exceptions might > > help in the bigger picture, splitting it up in smaller methods, etc. > > > > You can use catch/throw for this: > > I would recommend using an "ordinary" exception - because that's what it is. I would recommend not to use an exception at all. If I had the problem I would try to the following things in that order: (a) restructure your case if this makes it more readable (b) if not a local exit might make the code quite readable, if the case is used in a loop that well be "next", if the case is a method body, which is often the case use "return" (c) if neither (a) or (b) provide some appealing code, try to refactor the case into a method (d) and only if (c) makes no sense either use catch(:mylocalexit){ case.... throw :mylocalexit } HTH Robert -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein