D
Donkey Agony
Are the following two statements identical?
str = IO.read("test.txt")
str = File.read("test.txt")
I.e., do they both open the file for reading, slurp it into the string,
and close it?
They *appear* to be identical, judging from testing, but the docs are
unclear to me on this. E.g., the page on the IO class, which says ...
Many of the examples in this section use class File,
the only standard subclass of IO. The two classes are
closely associated.
...., shows IO.read, yet the page on the File class does not have a
File.read.
Also, there doesn't appear a similarly simple File.write that does all
the dirty work for you. The most concise I've come up with is:
File.open("test.html", "wb") { |f| f.write(str) }
Am I missing something?
str = IO.read("test.txt")
str = File.read("test.txt")
I.e., do they both open the file for reading, slurp it into the string,
and close it?
They *appear* to be identical, judging from testing, but the docs are
unclear to me on this. E.g., the page on the IO class, which says ...
Many of the examples in this section use class File,
the only standard subclass of IO. The two classes are
closely associated.
...., shows IO.read, yet the page on the File class does not have a
File.read.
Also, there doesn't appear a similarly simple File.write that does all
the dirty work for you. The most concise I've come up with is:
File.open("test.html", "wb") { |f| f.write(str) }
Am I missing something?