path-temp
File.path_temp
defines a temporary file path. It does not create the file. If,
after the do block, a file exists at that path then the file is deleted.
#!/usr/bin/ruby -w
require 'file/path-temp'
File.path_temp() do |path|
puts path
puts File.exist?(path)
File.write path, 'whatever'
puts File.exist?(path)
end
root
To put the path somewhere besides the current directory, use the root
option:
File.path_temp('root'=>'/tmp') do |path|
puts path
end
extension
To give the path an extension, use the ext
option:
File.path_temp('ext'=>'txt') do |path|
puts path
end
Installation
The usual:
sudo gem install path-temp
Or however you like to install gems. It's just a single file.
License
Open source, MIT license.
Author
Mike O'Sullivan
mike@idocs.com
History
version | date | notes |
---|
1.0 | Jun 29, 2023 | Initial upload. |