Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

File.truncate

File.truncate(file_name, integer) → 0

Truncates the file file_name to be at most integer bytes long. Not available on all platforms.

Example
f = File.new("out", "w")
f.write("1234567890")     #=> 10
f.close                   #=> nil
File.truncate("out", 5)   #=> 0
File.size("out")          #=> 5
See also #truncate .symlink? .umask .symlink also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0