title: Ruby - how to read first n lines from file into array
body: <p>For some reason, I can't find any tutorial mentioning how to do this...
  So, how do I read the first n lines from a file?</p>
  
  <p>I've come up with:</p>
  
  <pre><code>while File.open('file.txt') and count &lt;= 3 do |f|
    ...
      count += 1
    end
  end
  </code></pre>
  
  <p>but it is not working and it also doesn't look very nice to me.</p>
  
  <p>Just out of curiosity, I've tried things like:</p>
  
  <pre><code>File.open('file.txt').10.times do |f|
  </code></pre>
  
  <p>but that didn't really work either.</p>
  
  <p>So, is there a simple way to read just the first n lines without having to load the whole file?
  Thank you very much!</p>