Skip to content

Instantly share code, notes, and snippets.

@elcortez
Created April 10, 2019 17:16
Show Gist options
  • Select an option

  • Save elcortez/4525556de18abb6c709ed16812aa995e to your computer and use it in GitHub Desktop.

Select an option

Save elcortez/4525556de18abb6c709ed16812aa995e to your computer and use it in GitHub Desktop.
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