title: Ruby 1.9.3 - How does CSV.table know if no headers are in a CSV file?
body: <p>I have been doing some testing with <code>CSV.table</code>. I have two small and almost identical CSV files, however one is missing the header row.</p>
  
  <p>When I run <code>CSV.table</code> against the CSV file with the header row, everything works as expected.</p>
  
  <p>When I run it against the CSV file without the header row I get:</p>
  
  <pre><code>NoMethodError: undefined method `encode' for nil:NilClass
  </code></pre>
  
  <p>I tried this with different types of data, with different types of headers, and get the same results.</p>
  
  <p>I am curious to the magic of <code>CSV.table</code>. If I use <code>CSV.parse</code> with headers set to true, then it always makes the first row be headers no matter what. So, I have been using <code>CSV.table</code> to check if a CSV file being imported has a header row but I am not too comfortable with this because I don't understand if or when it will or will not work the way I'm using it.</p>
  
  <pre><code>begin
    CSV.table(csv_file_path)
  rescue
    # Add error to log or something.
  end
  </code></pre>
  
  <p>Does anyone know?</p>
  
  <p>P.S. I've already read through this and the source code it provides on each method - <a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV.html">http://www.ruby-doc.org/stdlib-1.9.3/libdoc/csv/rdoc/CSV.html</a></p>