Class: RpsGem::LetsPlay

Inherits:
Object
  • Object
show all
Defined in:
lib/rps_gem.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exampleObject



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)
  options = ["rock","paper","scissors"]
  player_choice = options.find_index {|choice| choice.match(/^#{player_op.downcase}/)}
  computer_choice = rand(options.length)
  return "Invalid Choice :P" if player_choice.nil?
  return "Tie!" if options[computer_choice]==options[player_choice]
  puts "Computer played #{options[computer_choice]}"
  return "You Won!" if self.winner(options[player_choice], options[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