Class: TicTacToe::Player

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

Direct Known Subclasses

Computer, Human

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Player

Returns a new instance of Player.



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

def initialize(name)
	@name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#symbolObject (readonly)

Returns the value of attribute symbol.



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

def symbol
  @symbol
end

Class Method Details

.create(name) ⇒ Object



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

def self.create(name)
	Module.const_get("TicTacToe::#{human?(name) ?  Human : Computer}").new(name)
end

Instance Method Details

#assign_symbol(player_1_symbol: nil) ⇒ Object



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

def assign_symbol(player_1_symbol: nil)
	@symbol = player_1_symbol ? Constants::ALLOWED_SYMBOLS.reject { |s| s == player_1_symbol }.first : Constants::ALLOWED_SYMBOLS.sample
end