Brian Candler
2/8/2007 12:43:00 PM
On Thu, Feb 08, 2007 at 07:52:41PM +0900, Erik Veenstra wrote:
> These are my personal implementations of Dir.home and Dir.temp.
ruby has the latter included as standard.
require 'tmpdir'
puts Dir.tmpdir
Here's the implementation from tmpdir.rb:
##
# Returns the operating system's temporary file path.
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
end
File.expand_path(tmp)
end