Class: Kaibaibo::Player

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

Direct Known Subclasses

CompPlayer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "mister_no_name") ⇒ Player

Returns a new instance of Player.



4
5
6
7
# File 'lib/kaibaibo/player.rb', line 4

def initialize(name = "mister_no_name")
  @name = name
  @status = nil
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/kaibaibo/player.rb', line 3

def name
  @name
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/kaibaibo/player.rb', line 3

def status
  @status
end

Class Method Details

.get_nameObject



13
14
15
16
# File 'lib/kaibaibo/player.rb', line 13

def self.get_name
  puts "What's your name?"
  gets.chomp
end

Instance Method Details

#gather_choiceObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kaibaibo/player.rb', line 18

def gather_choice
  puts "#{@name}, enter your choice"
  choice = gets.strip
  case choice
  when "rock"
    throw(:rock)
  when "paper"
    throw(:paper)
  when "scissors"
    throw(:scissors)
  else
    puts "Incorrect input"
    gather_choice
  end
end

#throw(choice) ⇒ Object



9
10
11
# File 'lib/kaibaibo/player.rb', line 9

def throw(choice)
  @status = choice
end