From: "Iñaki Baz Castillo" Date: 2011-07-14T18:38:21+09:00 Subject: Re: Why return(XXX) is valid within a "value = case N ..." ? 2011/7/14 Robert Klemme : > Could be that you have found a loophole in the parser logic. :-) XD >> I'm using Ruby 1.9.2 and in fact I use a method like "test2" it in my >> project, but it seems a bit strange for me and I would like to be sure >> that it's something correct (even if IMHO it does not make sense) and >> will not change in a future Ruby 1.9 version. > > I'd say stop using this idiom.  If you use a "case" expression because > it should yield a value (i.e. "x = case...end") then I would only use > exceptions as other way out.  A "return" indicates regular execution > flow which in the case of this usage of "case" would mean "have case > return a value" but not "return from the method". > > If you use "case" as a control flow construct (i.e. without assigning > the result) then a "return" inside is OK and Ruby will also accept it. >  Same goes for "if". Thanks, I'll make my code more "polite" then :) -- Iñaki Baz Castillo