1. If you do not understand this, go back through and use the comment trick to get it squared away in your mind. One simple english comment on each line will help you understand or at least let you know what you need to research more?
Do that if you don’t understand.
2. Write a script similar to the last exercise that uses read and argv to read the file you just created.
3. There’s too much repetition in this file. Use Strings, formats, and escapes to print out line1, line2, and line3 with just one target.write() instead of six.
I used concantenation and remove .chomp after gets. See the first picture for more info.
4. Find out why we had to pass a ‘w’ as an extra parameter to open. Hint: open tries to be safe by explicitly say you want to write a file.
By default, we can only read the file. Read 3rd picture for detail explanation and other methods for open.
5. If you open the file with ‘w’ mode, then do you really need the target.truncate()? Read the documentation for Ruby’s open function and see if that’s true.
There’s no need for truncate in ‘w’ mode. Read above for details.