Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 13
    great answer. Ruby conevntion is snake case for var names. Just a heads up for newbies. outFile should look like out_file. Commented Aug 8, 2013 at 10:46
  • 3
    @AdamWaite I edited the answer as per your snake_case suggestion, leaving this comment for context. Commented Aug 8, 2013 at 12:20
  • 6
    @zanbri - what happens if I don't close the file ? Commented Sep 27, 2014 at 7:18
  • 2
    @BoratSagdiyev "A File object which is no longer referenced becomes eligible for garbage collection. The file will be closed automatically when the File object is garbage collected." rootr.net/rubyfaq-9.html Commented Nov 19, 2015 at 6:45
  • 3
    @jkdev, yes, it will be closed, but it's still considered code smell to rely on that, just as if the programmer never closed files and let the OS close the files when the interpreter terminates. And both can lead to a bad bug if multiple files are opened and the code never closes them leading to an out-of-handles condition and error. It's just a better, safer, practice to deliberately close them or rely on a block that does so automatically. Commented Dec 6, 2019 at 19:31