From: dblack@... Date: 2007-08-09T20:06:42+09:00 Subject: Re: case statement Hi -- On Thu, 9 Aug 2007, Alex Young wrote: > Robert Klemme wrote: >> 2007/8/8, Shai Rosenfeld : >>> hi guys, >>> >>> was wondering the syntax of how to do this: >>> >>> case [1,2,3,4] >>> >>> when 1: 'this is what i want' >>> when 11: 'not result' >>> when 15: 'no good' >>> >>> end >>> >>> ((i.e, whatever value is included in the array)) >>> ...how do i do this? >> >> You can do it with the other form of "case": >> >> a = [1,2,3,4] >> result = case >> when a.include?(1): 'this is what i want' >> when a.include?(11): 'not result' >> when a.include?(15): 'no good' >> end > > Or the other way around: > > a = [1,2,3,4] > b = 2 > result = case b > when *a: "yes!" > else "no!" > end I had the impression that Shai wanted to check both for the inclusion of one item, and the absence of others. I'm not sure, since the original example was kind of pseudo-code based on what he wanted and it wasn't clear what should happen in a fall-through situation (which I know case doesn't do, but I think Shai was angling for that). David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)