class RpsRabGIT::RpsGame
Public Class Methods
new()
click to toggle source
# File lib/rps_rabGIT/rps_game.rb, line 4 def initialize @play_options = ['R', 'P', 'S'] @win_combos = ['RS', 'SP', 'PR'] @player_choice = '' @comp_choice = '' end
Public Instance Methods
play()
click to toggle source
# File lib/rps_rabGIT/rps_game.rb, line 11 def play @comp_choice = @play_options.sample() prompt until valid_move? return 'Tie!' if @player_choice == @comp_choice return "Your #{@player_choice} beat computer's #{@comp_choice}" if win? "Computer's #{@comp_choice} beat your #{@player_choice}!" end
Private Instance Methods
prompt()
click to toggle source
# File lib/rps_rabGIT/rps_game.rb, line 26 def prompt puts('Enter your choice (R/P/S): ') @player_choice = gets.strip.upcase end
valid_move?()
click to toggle source
# File lib/rps_rabGIT/rps_game.rb, line 21 def valid_move? return false unless @play_options.include?(@player_choice) true end
win?()
click to toggle source
# File lib/rps_rabGIT/rps_game.rb, line 31 def win? @win_combos.include?(@player_choice + @comp_choice) end