Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement