Reputation: 353
Can somebody please guide me a way to clean all existing content in a file before writing new info to it in Ruby? I'm writing the contents of this file with the code below:
logfile = File.new(filepath, "w")
logfile.write("my content")
However, I want all existing content in this "logfile" to be deleted before I write new info to it. How can I do this?
Upvotes: 6
Views: 5128
Reputation: 70949
When opening a file for writing, i.e. using the "w" option, all previous contents of the file will be removed so you don't have to do anything explicitly to achieve that effect.
Upvotes: 13