I am very new to Ruby and building my first game. To be honest I did it this way because I was lazy to type so much. My friend told me that the correct way was to do this with case statement i.e. for scissor we have three cases, for rock we have three cases and similarly for paper.puts Rock, paper or scissorw = 0 and l =0 and t =0 and j=0loop{choice = [paper , rock , scissor ]i=0if j ==10puts wins : #{w}\nlosses : #{l}\ndraw:    #{t}       if w > l            puts You won the game       elsif w<l            puts You lost!       else            puts The game is a draw       end         gets      break      end     while i == 0human = gets.chomp.downcasechoice.each {    |x|     if human == x        i+=1 and j+=1        break    end    }    puts -----------------please enter rock paper or scissor----------------- if i == 0endcomputer = rand(3)com = choice[computer]if (com == scissor and human != rock) or (human == scissor and computer !=1)   v = human <=> com  else    v = com <=> human endputs You chose #{human}, computer choose #{com}case v    when 1        puts ---->You win        w +=1    when -1        puts ---->Computer wins        l+=1    else        puts ---->draw        t+=1end}
Rock, Paper, Scissors game
beginner;ruby;game;rock paper scissors
IndentationBe sure to indent your code properly. Indentation helps the reader understand where he is in the code (how deep). Some languages actually depend on correct indentation.Meaningful namesYou should give your variable names which will have meaning, and will help the reader of your code understand what each one is responsible for. Names like w, t, j should not be used for any variable other than immediate throw-away variables like if for(i = 1;....A variable name l should never ever be used, since it is too easily confused with the digit 1, so in some fonts you will never know the difference between l+=1 and l+=l...Your code should tell a storyTry to design your code in a way that a reader will be able to follow your logic. In your code, there is an endless loop, and in the first if you check whether a mysterious j is 10, and if it is you end the game... The story starts with the ending!A more pleasing option might be:while number_of_turns_played < 10 do  # play a turn...  number_of_turns_played += 1endif number_of_wins > number_of_losses  puts You won the gameelsif number_of_wins < number_of_losses  puts You lost the gameelse  puts The game is a drawendThis way the story has a beginning, and an end, and it easier to follow.Choose your typesWhat is i used for? As far as I can see it can have only two values - 0 and 1, and it is used to flag the get input loop that a valid input has been received. The name i is cryptic enough - why not at least make it a boolean?Block format conventionsIt is idiomatic in ruby to use {} syntax for one liner blocks, and do end syntax for multiline blocks.Instead of writing:choice.each {  |x|  # do something}You should write:choice.each do |x|  # do somethingendToo sophisticated for your own goodLet's look at the condition you worked so hard on for being lazy:if (com == scissor and human != rock) or (human == scissor and computer !=1) v = human <=> comelse  v = com <=> humanendFirst - be consistent - on one side check com and on the other you check computer - choose!Using esoteric operators - the spaceship operator (a<=>b) is used when sorting arrays, and returns -1 if a is smaller than b, 1 if a is larger than b, and 0 if they are equal. It is very rarely used, and your usage, while cute, might be very unclear for most (I know I had to double check what it returns). Is it really needed?Assumptions - you rely on the fact that paper is smaller than rock, which is smaller than scissor, and you write your algorithm around that assumption. You are relying on an incidental fact, which might change when, say, you translate it to another language! Don't make incidental assumptions, use your code to define your rules.When there are too many exceptions to the rule - so you found a cool rule, which is good for [almost] all your cases. That is all but two, out of six... which is four... which is just about half the cases... Which you will need to explain to anybody who reads the code, since it is not apparent from how the code is written... Maybe it is not that good a rule?So, what would I suggest?Say I set the choices to %w(rock paper scissors), where each choice beats the one prior to it, now I can ask:computer_choice_idx = rand(3)if human_choice == choices[computer_choice_idx]  # draw!elsif human_choice == choices[computer_choice_idx - 1]  # computer beats human!else  # human beats computer!endSince in ruby choice[-1] returns the last element in the array (scissors), there is no exception! If the computer chose rock(id 0) and the human chose scissors - computer will beat human, since scissors == choices[-1].In short:Choices = %w(rock paper scissors)puts 'Rock, paper or scissors'draws = wins = losses = 010.times do  begin    puts -----------------please enter rock paper or scissors-----------------    human_choice = gets.chomp.downcase  end until Choices.include?(human_choice)  computer_choice_idx = rand(3)  puts You chose #{human_choice}, computer choose #{Choices[computer_choice_idx]}  if human_choice == Choices[computer_choice_idx]    puts ---->draw    draws += 1  elsif human_choice == Choices[computer_choice_idx - 1]    puts ---->Computer wins    losses += 1  else    puts ---->You win    wins += 1  endendputs wins : #{wins}\nlosses : #{losses}\ndraw:    #{draws}if wins > losses  puts You won the gameelsif wins < losses  puts You lost!else  puts The game is a drawendEnjoy!