From: Christopher Dicely Date: 2008-04-20T02:59:56+09:00 Subject: Re: How to "break" a "case-when" ? On Fri, Apr 18, 2008 at 1:40 PM, Robert Dober wrote: > > On Fri, Apr 18, 2008 at 8:52 PM, Iñaki Baz Castillo wrote: > > El Viernes, 18 de Abril de 2008, Peña, Botp escribió: > > > > > > > how about another case way, > > > > > > var = ...something... > > > case > > > when num==1 and ( var < 0 || var > 10 ) > > > puts "var not valid for num==1 !!!!!" > > > when other_stuff_condition > > > when .... > > > ... > > > else > > > else_stuff > > > end > > > puts "Write it" > > > > opss, I didn't know that a "when" can contain a comparision, nice to know! > It can contain any expression, but it will not do what you want. Sure it will. There are two different forms of case, the form case when foo1 then bar1 when foo2 then bar2 ... else baz end Works exactly as described above. You could do it with the other kind of case (the one whose semantics you describe), but it would be a bit uglier. E.g., case num when (if var.between? 0, 10 then 1 else Object.new) then do_normal_stuff when 1 then do_error_stuff ... end