Created
April 10, 2019 17:16
-
-
Save elcortez/4525556de18abb6c709ed16812aa995e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def game_refacto | |
| game_logic = { 'rock' => 'scissors', 'paper' => 'rock', 'scissors' => 'paper' } | |
| options = game_logic.keys | |
| computer_input = options.sample | |
| puts "#{options.join(', ')}?" | |
| player_input = gets.chomp.downcase | |
| win = "You win! Computer input was #{computer_input}" | |
| lose = "You lose! Computer input was #{computer_input}" | |
| draw = "Draw! Computer input was #{computer_input}" | |
| return "Wrong input" unless options.include?(player_input) | |
| return draw if player_input == computer_input | |
| return win if game_logic[player_input] == computer_input | |
| return lose | |
| end | |
| puts game_refacto |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment