From e6910571b4bb9f65a241df9ff28ff4cfbb832aa5 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 14 Apr 2015 17:57:55 -0400 Subject: Player: Add `initialize` method, use insignia constants Add an `initialize` method to get rid of our test errors and use the constants we created in 231060de4c493a9c6ba3510a9be4d405517af5c6 when creating new `Player`s. --- main.rb | 4 ++-- player.rb | 5 +++++ spec/player_spec.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/main.rb b/main.rb index ad9eb72..dedf9f7 100644 --- a/main.rb +++ b/main.rb @@ -2,8 +2,8 @@ require_relative 'board' require_relative 'player' board = Board.new -player_1 = Player.new('X', board) -player_2 = Player.new('O', board) +player_1 = Player.new(Player::INSIGNIAS[:x], board) +player_2 = Player.new(Player::INSIGNIAS[:o], board) board.current_player = player_1 until board.winner diff --git a/player.rb b/player.rb index 842e565..d19ee36 100644 --- a/player.rb +++ b/player.rb @@ -3,4 +3,9 @@ class Player :x => 'X', :o => 'O' } + + def initialize(insignia, board) + @insignia = insignia + @board = board + end end diff --git a/spec/player_spec.rb b/spec/player_spec.rb index 3306095..4dee7e7 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -16,7 +16,7 @@ describe Player do describe '#move' do before do board = Board.new - @player = Player.new('X', board) + @player = Player.new(Player::INSIGNIAS[:x], board) end it 'raises an ArgumentError given invalid coordinates' do -- cgit v1.2.3