Class: TicTacToe::Rules

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

Instance Method Summary collapse

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

#tieObject



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

#winnerObject



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