summaryrefslogtreecommitdiff
path: root/lib/tmpdir.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tmpdir.rb')
-rw-r--r--lib/tmpdir.rb22
1 files changed, 7 insertions, 15 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index 409d779..0b21f00 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -17,12 +17,12 @@ class Dir
##
# Returns the operating system's temporary file path.
- def Dir::tmpdir
+ def self.tmpdir
if $SAFE > 0
@@systmpdir
else
tmp = nil
- for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.']
+ [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp', '.'].each do |dir|
next if !dir
dir = File.expand_path(dir)
if stat = File.stat(dir) and stat.directory? and stat.writable? and
@@ -31,7 +31,7 @@ class Dir
break
end rescue nil
end
- raise ArgumentError, "could not find a temporary directory" if !tmp
+ raise ArgumentError, "could not find a temporary directory" unless tmp
tmp
end
end
@@ -81,8 +81,8 @@ class Dir
# FileUtils.remove_entry dir
# end
#
- def Dir.mktmpdir(prefix_suffix=nil, *rest)
- path = Tmpname.create(prefix_suffix || "d", *rest) {|n| mkdir(n, 0700)}
+ def Dir.mktmpdir(prefix_suffix="d", *rest)
+ path = Tmpname.create(prefix_suffix, *rest) {|n| mkdir(n, 0700)}
if block_given?
begin
yield path
@@ -122,15 +122,7 @@ class Dir
path << suffix
end
- def create(basename, *rest)
- if opts = Hash.try_convert(rest[-1])
- opts = opts.dup if rest.pop.equal?(opts)
- max_try = opts.delete(:max_try)
- opts = [opts]
- else
- opts = []
- end
- tmpdir, = *rest
+ def create(basename, tmpdir=nil, max_try: nil, **opts)
if $SAFE > 0 and tmpdir.tainted?
tmpdir = '/tmp'
else
@@ -139,7 +131,7 @@ class Dir
n = nil
begin
path = File.join(tmpdir, make_tmpname(basename, n))
- yield(path, n, *opts)
+ yield(path, n, opts)
rescue Errno::EEXIST
n ||= 0
n += 1