2
Dealing with the lifecycle of a Tempfile
source link: https://dev.to/olistik/dealing-with-the-lifecycle-of-a-tempfile-1lfk
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Dealing with the lifecycle of a Tempfile
Jul 23
・1 min read
When dealing with Tempfile
s in Ruby it's important to remember that when a tempfile object gets deallocated, the referenced file gets deleted as well.
require 'tempfile'
def foo
Tempfile.new.path
end
path = foo # => "/tmp/20210723-30107-1h52x7"
# Soon after:
File.exists?(path) # => true
# But wait for it..
File.exists?(path) # => false
Enter fullscreen modeExit fullscreen mode
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK