Ruby's Tempfile allows you to create temporary files, but what if you want to create temporary directories.
Dir#mktmpdir provides that functionality but with a caveat: if you pass a block to it, the directory will be automatically removed when the block finished, otherwise you have to clean up the directory yourself.
require 'fileutils'
require 'tmpdir' # needed to mix-in the mktmpdir method
begin
temp_dir = Dir.mktmpdir('my_temp_dir')
# do some work
ensure
FileUtils.remove_entry temp_dir
end