Returns the operating system’s temporary file path.
# File lib/tmpdir.rb, line 37 def Dir::tmpdir tmp = '.' if $SAFE > 0 tmp = @@systmpdir else for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], ENV['USERPROFILE'], @@systmpdir, '/tmp'] if dir and File.directory?(dir) and File.writable?(dir) tmp = dir break end end File.expand_path(tmp) end end
If you simply say Dir.tmpdir you might get a nice surprise:
irb> Dir.tmpdir NoMethodError: undefined method `tmpdir' for Dir:Class
Strangely, this method seems to be stored in a file that Ruby doesn’t require by default. Just require 'tmpdir' and all should be well.