Creating an empty file in Ruby: “touch” equivalent?

后端 未结 5 1186
心在旅途
心在旅途 2021-01-30 15:28

What is the best way to create an empty file in Ruby?

Something similar to the Unix command, touch:

touch file.txt
5条回答
  •  长情又很酷
    2021-01-30 16:00

    FileUtils.touch looks like what it does, and mirrors* the touch command:

    require 'fileutils'
    FileUtils.touch('file.txt')
    

    * Unlike touch(1) you can't update mtime or atime alone. It's also missing a few other nice options.

提交回复
热议问题