From: John Fink Date: 2006-08-10T01:50:59+09:00 Subject: Re: how to see if a variable matches an array element? ------=_Part_15313_3951765.1155142251504 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Yeehaw, that did it. Thanks David. jf On 8/9/06, dblack@wobblini.net wrote: > > Hi -- > > On Thu, 10 Aug 2006, John Fink wrote: > > > Hey folks, > > > > I'm knocking together a Rock, Paper, Scissors Ruby script to teach > myself > > more Ruby deliciousness, and I've got it working, except I want to > compare a > > variable to an array element (one of ["R", "P", "S"]) and have the > program > > die if it doesn't match up. > > > > Here's the relevant part of my script (note the rochambo function is > defined > > earlier in the script, and is really verbose, so I clipped it out): > > > > choices = %w{R P S} > > puts "Your choice? R,P,S" > > userchoice = gets.chomp.upcase > > raise unless choices.include?(userchoice) # or something like that > > > David > > -- > http://www.rubypowerandlight.com => Ruby/Rails training & consultancy > ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- > http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log > http://www.manning.com/black => book, Ruby for Rails > http://www.rubycentral.org => Ruby Central, Inc. > > ------=_Part_15313_3951765.1155142251504--