* lib/tempfile.rb: provide default basename parameter.

[fix GH-523] Patch by @dissolved
* test/test_tempfile.rb: ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2015-01-04 00:18:38 +00:00
parent b85a4eea55
commit 05c108cdba
3 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,9 @@
Sun Jan 4 09:18:31 2015 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/tempfile.rb: provide default basename parameter.
[fix GH-523] Patch by @dissolved
* test/test_tempfile.rb: ditto.
Sun Jan 4 00:43:41 2015 Ayumu AIZAWA <ayumu.aizawa@gmail.com>
* README.ja.md: add guidance of mailing list and bugs.r-l.o.

View File

@ -122,7 +122,7 @@ class Tempfile < DelegateClass(File)
#
# If Tempfile.new cannot find a unique filename within a limited
# number of tries, then it will raise an exception.
def initialize(basename, tmpdir=nil, mode: 0, **options)
def initialize(basename="", tmpdir=nil, mode: 0, **options)
if block_given?
warn "Tempfile.new doesn't call the given block."
end

View File

@ -57,6 +57,11 @@ class TestTempfile < Test::Unit::TestCase
assert_match(/^foo/, File.basename(t.path))
end
def test_default_basename
t = tempfile
assert File.exist?(t.path)
end
def test_basename_with_suffix
t = tempfile(["foo", ".txt"])
assert_match(/^foo/, File.basename(t.path))