+ 2

File.open or File.new?

What is the different between these methods?

29th Sep 2017, 8:12 AM
Vladimir Dabarov
Vladimir Dabarov - avatar
2 Answers
+ 13
You cannot open an existing file with File.new. File.open is used to open an existing file, and is a synonym for ::new when the specified file is found to be associated with no block. https://ruby-doc.org/core-2.1.4/File.html
29th Sep 2017, 8:27 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Thanks, I tried it in the sandbox and new didn't work. Even if the file doesn't exist.
29th Sep 2017, 8:42 AM
Vladimir Dabarov
Vladimir Dabarov - avatar