1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/tempfile.rb: provide default basename parameter

for Tempfile.create. [Feature #11965] Patch by Yuki Kurihara
* test/test_tempfile.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56251 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
sonots 2016-09-26 05:45:29 +00:00
parent 8d501ec021
commit 64f53f0dbf
3 changed files with 16 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Mon Sep 26 14:36:12 2016 Naotoshi Seo <sonots@gmail.com>
* lib/tempfile.rb: provide default basename parameter for
Tempfile.create. [Feature #11965] Patch by Yuki Kurihara
* test/test_tempfile.rb: ditto.
Mon Sep 26 14:10:54 2016 Ary Borenszweig <ary@esperanto.org.ar> Mon Sep 26 14:10:54 2016 Ary Borenszweig <ary@esperanto.org.ar>
* string.c (lstrip_offset): add a fast path in the case of single * string.c (lstrip_offset): add a fast path in the case of single

View file

@ -323,7 +323,7 @@ end
# ... do something with f ... # ... do something with f ...
# end # end
# #
def Tempfile.create(basename, tmpdir=nil, mode: 0, **options) def Tempfile.create(basename="", tmpdir=nil, mode: 0, **options)
tmpfile = nil tmpfile = nil
Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts| Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts|
mode |= File::RDWR|File::CREAT|File::EXCL mode |= File::RDWR|File::CREAT|File::EXCL

View file

@ -345,5 +345,14 @@ puts Tempfile.new('foo').path
f.close if f && !f.closed? f.close if f && !f.closed?
File.unlink path if path File.unlink path if path
end end
def test_create_default_basename
path = nil
Tempfile.create {|f|
path = f.path
assert_file.exist?(path)
}
assert_file.not_exist?(path)
end
end end