I'm going through "Learn Ruby the Hard Way" and I can't get my Windows command prompt to display the docs for: ri File.open
It just gives me an error:
ArgumentError: wrong number of arguments (0 for 1..3)
I'm currently on exercise 16: http://ruby.learncodethehardway.org/book/ex16.html
And the extra credit says: If you open the file with 'w' mode, then do you really need the target.truncate()? Go read the docs for Ruby's File.open function and see if that's true.
where can I see the docs for the File.open function?
Read the documentation of IO, File's parent class. It describes the file opening modes you mentioned in your question. Here's the description for the w opening mode:
"w" Write-only, truncates existing file
to zero length or creates a new file for writing.
So no, you don't really need to call target.truncate if you open the file in w mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With