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
18 19 20 21 |
# File 'lib/rps_gem.rb', line 18 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 |
# 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) return "Invalid Choice :P" if player_choice.nil? return "Tie!" if [computer_choice]==[player_choice] puts "Computer played #{[computer_choice]}" return "You Won!" if self.winner([player_choice], [computer_choice]) "You Loose!" end |
#winner(user, comp) ⇒ Object
14 15 16 |
# File 'lib/rps_gem.rb', line 14 def winner(user, comp) ["rockscissors", "scissorspaper", "paperrock"].include?(user+comp) end |