Class: RpsGem::LetsPlay
- Inherits:
-
Object
- Object
- RpsGem::LetsPlay
- Defined in:
- lib/rps_gem.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.example ⇒ Object
28 29 30 31 |
# File 'lib/rps_gem.rb', line 28 def self.example path = File.dirname(__FILE__) system(" man #{path}/rps_gem_man") end |
Instance Method Details
#play(player_op) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rps_gem.rb', line 3 def play(player_op) = ["rock","paper","scissors"] player_choice = .find_index {|choice| choice.match(/^#{player_op.downcase}/)} computer_choice = rand(.length) if player_choice.nil? "Invalid Choice :P" else if([computer_choice]==[player_choice]) "Tie!" else puts "Computer plyaed #{options[computer_choice]}" if(self.winner([player_choice], [computer_choice])==[player_choice]) "You Won!" else "You Loose!" end end end end |
#winner(p1, p2) ⇒ Object
23 24 25 26 |
# File 'lib/rps_gem.rb', line 23 def winner(p1, p2) wins = {rock: :scissors, scissors: :paper, paper: :rock} {true => p1, false => p2}[wins[p1] == p2] end |