title: How to make a general method to check for winners in Tic-Tac-Toe
body: <p>I made a Tic-Tac-Toe game in Ruby. The method below checks for a winner in the vertical columns.</p>
  
  <p>How do I make it so that this method can be applied to boards of different sizes, like 4x4, 6x6?</p>
  
  <pre><code>def vertical_check(array)
  
    result = nil
  
    if (array[0][0] == "X" &amp;&amp; array[1][0] == "X" &amp;&amp; array[2][0] == "X") ||
      (array[0][1] == "X" &amp;&amp; array[1][1] == "X" &amp;&amp; array[2][1] == "X") ||
      (array[0][2] == "X" &amp;&amp; array[1][2] == "X" &amp;&amp; array[2][2] == "X")
  
      result = "X"
  
    elsif (array[0][0] == "O" &amp;&amp; array[1][0] == "O" &amp;&amp; array[2][0] == "O") ||
      (array[0][1] == "O" &amp;&amp; array[1][1] == "O" &amp;&amp; array[2][1] == "O") ||
      (array[0][2] == "O" &amp;&amp; array[1][2] == "O" &amp;&amp; array[2][2] == "O")
  
      result = "O"
    else
      result = nil
    end
    return result
  end
  </code></pre>
  
  <p>The following is a failed attempt:</p>
  
  <pre><code>def vertical_check_x(array)
  
    result = nil
  
    index = 0
    index2 = 0
  
    until result != nil || index == array.length
  
      while array[index][index2] == "X"
        index += 1
      end
  
      if index == array.length
        result = "X"
      else
        result = nil
        index = array.length
      end
  
      index2 += 1
    end
  
    return result
  end
  
  def vertical_check_o(array)
  
    result = nil
  
    index = 0
    index2 = 0
    until result != nil || index == array.length
  
      while array[index][index2] == "O"
        index += 1
      end
  
      if index -1 == array.length
        result = "O"
      else
        result = nil
        index = array.length
      end
  
      index2 += 1
    end
  
    return result
  end
  
  def vertical_check(array)
  
    result = vertical_check_x(array)
  
    if result == nil
      result = vertical_check_o(array)
    end
  
    return result
  end
  </code></pre>