class Rockpapsciss::Player

Attributes

move[RW]
name[RW]

Public Class Methods

new(name) click to toggle source
# File lib/rockpapsciss.rb, line 7
def initialize(name)
  @move = nil
  @name = name
end

Public Instance Methods

get_move() click to toggle source
# File lib/rockpapsciss.rb, line 30
def get_move
  user_input = gets.chomp.upcase
  if valid_input?(user_input)
    @move = user_input
  else
    print "Not a valid input!\n"
    get_move
  end
end
valid_input?(move) click to toggle source

checks “move” argument if it’s valid move

# File lib/rockpapsciss.rb, line 17
def valid_input?(move)
  if move == "R" || move == "ROCK"
    return true
  elsif move == "P" || move == "PAPER"
    return true
  elsif move == "S" || move == "SCISSORS"
    return true
  else
    false
  end
end