Tic-Tac-Toe Win Detection: Diagonals

Hi,

I’m a bit confused about how the win detection for diagonals works in the given tic-tac-toe solution.

The below line of code seems to assume that diagonals is a triple:

(grid + cols + diagonals).each do |triple|

But diagonals seems to return an array of two triples. Won’t this mean that the code will try to compare an array of triples to a winning triple, and always return false?

What I did was to create an array by means of a loop in order to capture the diagonals.
Seems to work swell
I had recalled this method from an old problem involving grids - to go, for instance, “south-east” on a grid, one must increment both the X and Y coordinates in a linear fashion.

grid = [
[4, 2, 6],
[7, 6, 5],
[6, 8, 9]
]
(0…grid.length).each {|x| y = x; diag1 << grid[x][y]}
The result being [4, 6, 9]

I hope that this insight proves useful to folks browsing the forum