Class: TicTacToe::Rules
- Inherits:
-
Object
- Object
- TicTacToe::Rules
- Defined in:
- lib/tic_tac_toe/rules.rb
Instance Method Summary collapse
-
#initialize(board) ⇒ Rules
constructor
A new instance of Rules.
- #tie ⇒ Object
- #winner ⇒ Object
Constructor Details
#initialize(board) ⇒ Rules
Returns a new instance of Rules.
5 6 7 |
# File 'lib/tic_tac_toe/rules.rb', line 5 def initialize(board) @board = board end |
Instance Method Details
#tie ⇒ Object
14 15 16 17 18 19 |
# File 'lib/tic_tac_toe/rules.rb', line 14 def tie (1..9).each do |position| return false if @board.get_mark_at(position).nil? end return true end |
#winner ⇒ Object
9 10 11 12 |
# File 'lib/tic_tac_toe/rules.rb', line 9 def winner return "tie" if tie ["X", "O"].detect { |mark| winning_mark?(mark) } end |