Suppose there are two kinds of ruby file operations.
Firstly,
file = File.open("xxx")
file.close
Secondly,
file = File.read("xxx")
file.close
Everyone knows that we must close the file after we finish it. But in the second block of code, the Ruby interpreter produces the error message shown below:
in `<main>': undefined method `close' for
I do not need to use file.closein the second case? I wonder why?
source
share