class method
Dir.tmpdir
() -> ::String
tmpdir
lib/tmpdir.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/tmpdir.rb, line 25
def self.tmpdir
Tmpname::TMPDIR_CANDIDATES.find do |name, dir|
unless dir
next if !(dir = ENV[name] rescue next) or dir.empty?
end
dir = File.expand_path(dir)
stat = File.stat(dir) rescue next
case
when !stat.directory?
warn "#{name} is not a directory: #{dir}"
when !File.writable?(dir)
# We call File.writable?, not stat.writable?, because you can't tell if a dir is actually
# writable just from stat; OS mechanisms other than user/group/world bits can affect this.
warn "#{name} is not writable: #{dir}"
when stat.world_writable? && !stat.sticky?
warn "#{name} is world-writable: #{dir}"
else
break dir
end
end or raise ArgumentError, "could not find a temporary directory"
end
Returns the operating system’s temporary file path.
Example
require 'tmpdir' Dir.tmpdir # => "/tmp"