title: Why is my attr_accessor variable returning nil?
body: <p>I am practicing my ruby skills after a long while from backpacking and I think I am way rustier than I thought. The following code below is a connect 4 game that I am trying to implement for Code Wars. While doing coding this, I am having a problem with the <code>attr_accessor: turn_counter</code>.</p>
  
  <p>I have declared this variable as such, so I can increment it but when I call <code>turn_tracker.odd?</code> I receive a value of nil. Why is that? All my other variables are able to read/write respectively. For example, the <code>grid</code> is able to be called and returns the expected value. I don't see why turn_tracker should need the <code>self</code> call. The other variables don't need to. Can I get a refresher as to why that is? Thanks.   </p>
  
  <pre><code>class Connect4
  
  
  attr_reader :player_one, :player_two
    attr_accessor :turn_tracker, :grid
  
    def initialize
      @player_one = Player.new("Player 1")
      @player_two = Player.new("Player 2")
      @turn_tracker = 1
      @grid = [[],[],[],[],[],[]]
    end
  
    def play(column)
  
      ######### Problem ##############
      if turn_tracker.odd?
        self.turn_tracker += 1
      ################################    
  
        player_one.makes_a_move(grid[column])
        win?(grid[column], player_one)
      else
        self.turn_tracker += 1
        player_two.makes_a_move(grid[column])
        win?(grid[column], player_two)
      end
    end
  
    private
  
    def win?(grid, player)
      #vertical
      if grid.count(player) == 4
        player_indexes = grid.each_index.select do |i|
          grid[i].name == player.name
        end
  
        one = (player_indexes[0].next == player_indexes[1])
        two = (player_indexes[1].next == player_indexes[2])
        three = (player_indexes[2].next == player_indexes[3])
  
        if (one &amp;&amp; two &amp;&amp; three)
          "#{player.name} wins!"
        elsif column_full?(grid)
          "Column full!"
        else
          "#{player.name} has a turn"
        end
      else
        "#{player.name} has a turn"
      end
    end
  
    def column_full?(grid)
      grid.size == 7
    end
  end
  
  class Player
    attr_reader :name
  
    def initialize(name)
      @name = name
    end
  
    def makes_a_move(grid)
      grid &lt;&lt; self
    end
  end
  
  puts "New game!"
  game = Connect4.new
  puts game.play(0) #"Should return 'Player 1 has a turn'
  puts game.play(0) #"Should return 'Player 2 has a turn'
  
  puts "New game!"
  game = Connect4.new
  
  puts game.play(0) #"Should return 'Player 1 has a turn'
  puts game.play(1) #"Should return 'Player 2 has a turn'
  puts game.play(0) #"Should return 'Player 1 has a turn'
  puts game.play(1) #"Should return 'Player 2 has a turn'
  puts game.play(0) #"Should return 'Player 1 has a turn'
  puts game.play(1) #"Should return 'Player 2 has a turn'
  puts game.play(0) #"Player 1 wins!", "Player 1 wins!'
  
  
  puts "New game"
  game = Connect4.new
  puts game.play(4) #"Player 1 has a turn"
  puts game.play(4) #"Player 2 has a turn"
  puts game.play(4) #"Player 1 has a turn"
  puts game.play(4) #"Player 2 has a turn"
  puts game.play(4) #"Player 1 has a turn"
  puts game.play(4) #"Player 2 has a turn"
  puts game.play(4) # "Column full!"
  </code></pre>