diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 55920a4..9f8f6b0 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -19,10 +19,11 @@ class Dir # Returns the operating system's temporary file path. def self.tmpdir - ['TMPDIR', 'TMP', 'TEMP', ['system temporary path', @@systmpdir], ['/tmp']*2, ['.']*2].find do |name, dir| - unless dir - next if !(dir = ENV[name]) or dir.empty? - end + candidate_dirs = ['TMPDIR', 'TMP', 'TEMP'].map(&ENV.method(:[])) + fallback_dirs = [@@systmpdir, '/tmp', '.'] + + (candidate_dirs + fallback_dirs).find do |dir| + next if !dir or dir.empty? dir = File.expand_path(dir) stat = File.stat(dir) rescue next case