Created
July 8, 2013 01:50
-
-
Save robyurkowski/5945704 to your computer and use it in GitHub Desktop.
Tic Tac Toe Board
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Board | |
def initialize | |
self.squares = Array.new(9) | |
end | |
def rows | |
self.squares.each_slice(3) | |
end | |
def cols | |
rows.transpose | |
end | |
def diagonals | |
[[self.squares[0], self.squares[4], self.squares[8], [self.squares[2], self.squares[4], self.squares[6]] | |
end | |
def inspect | |
rows.map {|row| row + "\n" } | |
end | |
private | |
attr_accessor :squares | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment