Class: TicTacToe::Player
- Inherits:
-
Object
- Object
- TicTacToe::Player
- Defined in:
- lib/tic_tac_toe/player.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Class Method Summary collapse
Instance Method Summary collapse
- #assign_symbol(player_1_symbol: nil) ⇒ Object
-
#initialize(name) ⇒ Player
constructor
A new instance of Player.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/tic_tac_toe/player.rb', line 3 def name @name end |
#symbol ⇒ Object (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
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 |