From: Adam Bender Date: 2009-04-30T13:27:58+09:00 Subject: Read and re-write file with one open? --001636c5ad4db891040468be1e72 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit I would like to write a Ruby script that opens a text file, performs a gsub on each line, and then overwrites the file with the updated contents. Right now I open the file twice: once to read and once to write. The reason for this is that if I try to perform both operations on the same IO object by calling io.rewind and writing from the beginning, and the substituted word is shorter than what it is replacing, some portion of the end of the original file remains. Is there an idiom for "clearing" the contents of the file before writing? Thanks, Adam --001636c5ad4db891040468be1e72--