Skip to content
instance method

File#truncate

(::int length) -> 0
file.truncate(integer) → 0

Truncates file to at most integer bytes. The file must be opened for writing. Not available on all platforms.

Example
f = File.new("out", "w")
f.syswrite("1234567890")   #=> 10
f.truncate(5)              #=> 0
f.close()                  #=> nil
File.size("out")           #=> 5
See also .truncate #size #mtime also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0