title: Ruby's File.open and the need for f.close
body: <p>It's common knowledge in most programming languages that the flow for working with files is open-use-close. Yet I saw many times in ruby codes unmatched File.open calls, and moreover I found <a href="http://www.ruby-doc.org/core/classes/IO.html#M000939">this gem of knowledge</a> in the ruby docs:</p>
  
  <blockquote>
    <p>I/O streams are automatically closed when they are claimed by the garbage collector.</p>
  </blockquote>
  
  <p><strong>darkredandyellow</strong> friendly irc take on the issue:<br>
  [17:12]  yes, and also, the number of file descriptors is usually limited by the OS<br>
  [17:29]  I assume you can easily run out of available file descriptors <em>before</em> the garbage collector cleans up. in this case, you might want to use close them yourself. "claimed by the garbage collector." means that the GC acts at some point in the future. and it's expensive. a lot of reasons for explicitly closing files.</p>
  
  <ol>
  <li>Do we need to explicitly close</li>
  <li>If yes then why does the GC autoclose ?</li>
  <li>If not then why the option?</li>
  </ol>