diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-21 01:40:21 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-21 01:40:21 +0000 |
commit | a718be06fac884b62435a7fc9bb251131163c06e (patch) | |
tree | 82b09c64301c444dd3aaf639ed82047ab661840e /lib | |
parent | 09e91be9abbaa7e363d15ba6654afc9e667af4aa (diff) | |
download | ruby-a718be06fac884b62435a7fc9bb251131163c06e.tar.gz |
tempfile.rb: fix r47655
* lib/tempfile.rb (Tempfile#initialize, Tempfile.create): get rid of
shadowing local variables.
* lib/tmpdir.rb (Dir::Tmpname#make_tmpname): simlify argument
splitting.
* test/test_tempfile.rb: need thread library for ConditionVariable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47656 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tempfile.rb | 8 | ||||
-rw-r--r-- | lib/tmpdir.rb | 15 |
2 files changed, 7 insertions, 16 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 0d3c2a3901..64441511fe 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -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, **opts) + def initialize(basename, tmpdir=nil, mode: 0, **options) if block_given? warn "Tempfile.new doesn't call the given block." end @@ -130,7 +130,7 @@ class Tempfile < DelegateClass(File) @clean_proc = Remover.new(@data) ObjectSpace.define_finalizer(self, @clean_proc) - ::Dir::Tmpname.create(basename, tmpdir, opts) do |tmpname, n, opts| + ::Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts| mode |= File::RDWR|File::CREAT|File::EXCL opts[:perm] = 0600 @data[1] = @tmpfile = File.open(tmpname, mode, opts) @@ -347,9 +347,9 @@ end # ... do something with f ... # end # -def Tempfile.create(basename, tmpdir=nil, mode: 0, **opts) +def Tempfile.create(basename, tmpdir=nil, mode: 0, **options) tmpfile = nil - Dir::Tmpname.create(basename, tmpdir, opts) do |tmpname, n, opts| + Dir::Tmpname.create(basename, tmpdir, options) do |tmpname, n, opts| mode |= File::RDWR|File::CREAT|File::EXCL opts[:perm] = 0600 tmpfile = File.open(tmpname, mode, opts) diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 0b21f00d8e..7bd99e1fbb 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -105,21 +105,12 @@ class Dir Dir.tmpdir end - def make_tmpname(prefix_suffix, n) - case prefix_suffix - when String - prefix = prefix_suffix - suffix = "" - when Array - prefix = prefix_suffix[0] - suffix = prefix_suffix[1] - else - raise ArgumentError, "unexpected prefix_suffix: #{prefix_suffix.inspect}" - end + def make_tmpname((prefix, suffix), n) t = Time.now.strftime("%Y%m%d") path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}" path << "-#{n}" if n - path << suffix + path << suffix if suffix + path end def create(basename, tmpdir=nil, max_try: nil, **opts) |