From: dblack@... Date: 2007-08-08T23:27:34+09:00 Subject: Re: case statement Hi -- On Wed, 8 Aug 2007, Alex Young wrote: > Shai Rosenfeld wrote: >> Alex Young wrote: >>> Shai Rosenfeld wrote: >>>> end >>>> >>>> ((i.e, whatever value is included in the array)) >>>> ...how do i do this? >>> Does the Array#include? method do what you need? Perhaps a more >>> fleshed-out example might help? >> >> Array#include is EXACTLY what i need, but syntaxtetically (if u get the >> drift) i'm not sure how to do it: >> >> case [3, 45, 6, 'abc'].inlcude? >> when 1: 'no good' >> when 3: 'good!' >> when 'lolo': 'no good' >> end > I'm not sure why you're using case here. I'd do it like this: > > [3, 45, 6, 'abc'].include?(var) ? "good" : "no good" I think the problem is that if it includes both 1 and 3, it's no good. You (Shai) could do something like: module YesNo def yes_no(a,b) [*a].all? {|e| include?(a) } and not [*b].any? {|e| include?(e) } end end a = [1,2,3,4,5] a.extend(YesNo) p a.yes_no(3,6) # true p a.yes_no(3,5) # false (Those two lines are my only tests at the moment so try it out some more :-) 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)