title: How do I detect end of file in Ruby?
body: <p>I wrote the following script to read a CSV file:</p>
  
  <pre><code>f = File.open("aFile.csv")
  text = f.read
  text.each_line do |line|
    if (f.eof?)
      puts "End of file reached"
    else
      line_num +=1
      if(line_num &lt; 6) then
        puts "____SKIPPED LINE____"
        next
      end
    end
  
    arr = line.split(",")
    puts "line number  = #{line_num}" 
  end
  </code></pre>
  
  <p>This code runs fine if I take out the line:</p>
  
  <pre><code> if (f.eof?)
       puts "End of file reached"
  </code></pre>
  
  <p>With this line in I get an exception.</p>
  
  <p>I was wondering how I can detect the end of file in the code above.</p>