Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit 91764b5

Browse files
committed
Extract winning_player method
1 parent 37bb1a1 commit 91764b5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tic-tac-toe/tic_tac_toe.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ def winning_move?(square, player)
2727

2828
def winner
2929
square = 0
30-
if board[square] != '-' && board[square] == board[square + 1] && board[square + 1] == board[square + 2]
31-
return board[square]
32-
end
30+
return winning_player(square) if winning_player(square)
3331
square = 3
34-
if board[square] != '-' && board[square] == board[square + 1] && board[square + 1] == board[square + 2]
35-
return board[square]
36-
end
32+
return winning_player(square) if winning_player(square)
3733
square = 6
34+
return winning_player(square) if winning_player(square)
35+
return '-'
36+
end
37+
38+
def winning_player(square)
3839
if board[square] != '-' && board[square] == board[square + 1] && board[square + 1] == board[square + 2]
3940
return board[square]
4041
end
41-
return '-'
4242
end
4343

4444
def square_unoccupied?(square)

0 commit comments

Comments
 (0)