Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. def game_refacto
  2. game_logic = { 'rock' => 'scissors', 'paper' => 'rock', 'scissors' => 'paper' }
  3. options = game_logic.keys
  4. computer_input = options.sample
  5.  
  6. puts "#{options.join(', ')}?"
  7. player_input = gets.chomp.downcase
  8.  
  9. win = "You win! Computer input was #{computer_input}"
  10. lose = "You lose! Computer input was #{computer_input}"
  11. draw = "Draw! Computer input was #{computer_input}"
  12.  
  13. return "Wrong input" unless options.include?(player_input)
  14. return draw if player_input == computer_input
  15. return win if game_logic[player_input] == computer_input
  16. return lose
  17. end
  18.  
  19. puts game_refacto
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement