------ art_15329_16707606.1155142422356 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline And that too. As always, more than one way to skin a cat. I had totally forgotten about unless somehow. Thanks everybody. jf On 8/9/06, Justin Collins <collinsj / seattleu.edu> wrote: > > 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 ets.chomp.upcase > > computerchoice hoices[rand(choices.length)] > > puts "You picked " + userchoice + "!" > > puts "Computer picked " + computerchoice + "!" > > puts "FIGHT!" > > rochambo(userchoice, computerchoice) > > > > > > Basically I want to have the program die if the userchoice variable > > doesn't > > equal one of the elements in the choices array, and it should be easy, > > but I > > am hitting my head against a wall. > > > > jf > > > > Something like: > > unless choices.include? userchoice > puts "You must choose R, P, or S!" > exit > end > > -Justin > > ------ art_15329_16707606.1155142422356--