Module: PrivateMethods
- Defined in:
- lib/PrivateMethods.rb
Overview
add module for private methods for the rpsg calculations
Class Method Summary collapse
-
.final_outcome(pl, co) ⇒ Object
define final outcome that gives the result of who one the whole match.
-
.player_choice ⇒ Object
make a definition that asks for the players choice.
-
.player_outcome(plays) ⇒ Object
define outcomes of players choice against cpu.
Class Method Details
.final_outcome(pl, co) ⇒ Object
define final outcome that gives the result of who one the whole match
26 27 28 29 30 31 |
# File 'lib/PrivateMethods.rb', line 26 def final_outcome(pl, co) return :WIN if pl > co return :LOSE if pl < co # return :TIE if pl = co # there will never be a tie for the final outcome due to the code in the `play()` method end |
.player_choice ⇒ Object
make a definition that asks for the players choice
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/PrivateMethods.rb', line 6 def player_choice loop do print "\nChoose: Rock (r), Paper (p), or Scissors (s): " choice = gets.chomp.downcase if ProtectedConstants::NTRY_TO_SYM.key?(choice) return ProtectedConstants::NTRY_TO_SYM[choice] elsif choice != ProtectedConstants::VALID_ENTRIES puts "\nThat entry is invalid. Please re-enter.\n" else return nil end end end |
.player_outcome(plays) ⇒ Object
define outcomes of players choice against cpu
20 21 22 23 24 |
# File 'lib/PrivateMethods.rb', line 20 def player_outcome(plays) return :WIN if ProtectedConstants::WINNERS.include?(plays) return :LOSE if ProtectedConstants::LOSERS.include?(plays) return :TIE if !:WIN | !:LOSE end |