summaryrefslogtreecommitdiff
path: root/lib/tempfile.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r--lib/tempfile.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 7765026b47..601bb8d2f8 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -29,7 +29,12 @@ class Tempfile < DelegateClass(File)
# Dir::tmpdir provided by 'tmpdir.rb'.
# When $SAFE > 0 and the given tmpdir is tainted, it uses
# /tmp. (Note that ENV values are tainted by default)
- def initialize(basename, tmpdir=Dir::tmpdir)
+ def initialize(basename, *rest)
+ # I wish keyword argument settled soon.
+ if opts = Hash.try_convert(rest[-1])
+ rest.pop
+ end
+ tmpdir = rest[0] || Dir::tmpdir
if $SAFE > 0 and tmpdir.tainted?
tmpdir = '/tmp'
end
@@ -56,7 +61,12 @@ class Tempfile < DelegateClass(File)
@clean_proc = Tempfile.callback(@data)
ObjectSpace.define_finalizer(self, @clean_proc)
- @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
+ if opts.nil?
+ opts = []
+ else
+ opts = [opts]
+ end
+ @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600, *opts)
@tmpname = tmpname
@@cleanlist << @tmpname
@data[1] = @tmpfile