How do I create a temporary directory in Ruby in a nice way? I would also like to delete it automatically on process exit. Thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See documentation for tmpdir. If
mktmpdirmethod is provided with a block, the temp dir will be removed when block returns. In your case, you would call without a block and handle removal later (=program exit).Regarding automatic removal on exit, I think tmpdir won’t do that for you. However, at_exit should help.
As an example, Homebrew does it like this: