From: Robert Dober Date: 2008-04-19T05:40:57+09:00 Subject: Re: How to "break" a "case-when" ? 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. The semantics of case is the following case e when e1 a1 when e2 a2 else a3 end if e1 === e then a1 elsif e2 === e then a2 else a3 end unfortunately case e when true a will only work for e == true as true === Object.new --> false maybe Matz did not want to allow logical comparision in case ;) but he gave us the power to overrule try the following code with the line commented and then uncommented and you will see what is going on class TrueClass # def === any; true end end case 42 when true p true else p :else end HTH R. -- http://ruby-smalltalk.blogspot.com/ --- Whereof one cannot speak, thereof one must be silent. Ludwig Wittgenstein