Is there a way to simple erase text from the file?
Thanks,
Lucas
--
Posted via http://www.ruby-forum.com/.
File.open('file.txt', 'w') { |file| file = nil }
That reopens the file. Is there a way to do it without reopening?
The "file = nil" part is completely unneccessary. You can just do
File.open('file.txt', 'w') {}
> Is there a way to do it without reopening?
I don't think there is.
HTH,
Sebastian
--
NP: Depeche Mode - Freestate
Jabber: sep...@jabber.org
ICQ: 205544826
Ok, thank you :-)
Andrea
perhaps File#truncate
---------------------------------------------------------- File#truncate
file.truncate(integer) => 0
------------------------------------------------------------------------
Truncates _file_ to at most _integer_ bytes. The file must be
opened for writing. Not available on all platforms.
f = File.new("out", "w")
f.syswrite("1234567890") #=> 10
f.truncate(5) #=> 0
f.close() #=> nil
File.size("out") #=> 5
Guy Decoux
The documentation says this is platform specific, which I'd like to
avoid.
File.open will have to do.