class TicTacToe::Square
Attributes
number[R]
player[R]
Public Class Methods
new(board, number, saved=nil)
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 7 def initialize(board, number, saved=nil) @board = board @number = number @player = saved @lines = [] end
Public Instance Methods
<<(line)
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 18 def <<(line) @lines << line end
==(other)
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 14 def ==(other) other.player == player end
empty?()
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 33 def empty? player.nil? end
line_count()
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 22 def line_count @lines.size end
serialize()
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 45 def serialize player end
take(player)
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 26 def take(player) raise IllegalMoveError, 'Square already taken' unless empty? @player = player notify end
taken_by?(player)
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 37 def taken_by?(player) self.player == player end
taken_by_opponent?(player)
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 41 def taken_by_opponent?(player) !empty? && !taken_by?(player) end
Private Instance Methods
notify()
click to toggle source
# File lib/tic_tac_toe_mchliakh/board/square.rb, line 51 def notify ([@board] + @lines).map(&:square_taken) end