[Battleship] Bonus Question

I’m almost through refactoring my Battleship so that it can be a HumanPlayer vs a ComputerPlayer, but I’ve run into an issue with referencing grid coordinates. The following code is part of my player.rb file that is supposed to determine whether a ship can be placed on the grid by player (making sure there aren’t any other ships in the way), where position is the left-most coordinate.

  def h_fit?(ship, position)
    if (position[1]...(position[1] + ship.length)).to_a.any? do |col|
      board[[position[0], col]] == :s
    end || position[1] + ship.length > 10
      false
    else
      true
    end
  end

I also made sure to have the following code for the syntactic sugar regarding the bracket syntax in my board.rb file:

  def [](pos)
    row, col = pos
    @grid[row][col]
  end

  def []=(pos, mark)
    row, col = pos
    @grid[row][col] = mark
  end

I end up getting the following error when I try to run the code:

/home/jonathan/AppAcademy/alpha_exercises/04d1419d-jonathan.liu137-battleship/lib/board.rb:28:in[]’: undefined method []' for nil:NilClass (NoMethodError)

The “board.rb:28” refers to the @grid[row][col] in def [](pos).

I found the error really odd because when I go in with byebug and check everything used in the code, nothing is “nil” except for all the coordinates on the board’s grid (which they should be). Could anyone give me some insight into why I am running into this error?

What’s going on with the:

 end || position[1] + ship.length > 10