diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-18 10:32:26 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-18 10:32:26 +0000 |
commit | 88aa8632741d027d1d2e58f8073d4ec90845499d (patch) | |
tree | 4933e3d7f3119faec3a563ca15570d3adc8ee219 /lib/tempfile.rb | |
parent | fcce99c52d786e336ab0a8f8205a04841fc743d0 (diff) | |
download | ruby-88aa8632741d027d1d2e58f8073d4ec90845499d.tar.gz |
* lib/tempfile.rb (Tempfile#initialize): now Tempfile.new takes
keyword arguments to open(). [ruby-dev:36756]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r-- | lib/tempfile.rb | 14 |
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 |