ruby-changes:35574
From: nobu <ko1@a...>
Date: Sun, 21 Sep 2014 10:40:37 +0900 (JST)
Subject: [ruby-changes:35574] nobu:r47656 (trunk): tempfile.rb: fix r47655
nobu 2014-09-21 10:40:21 +0900 (Sun, 21 Sep 2014) New Revision: 47656 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47656 Log: 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. Modified files: trunk/lib/tempfile.rb trunk/lib/tmpdir.rb trunk/test/test_tempfile.rb Index: lib/tempfile.rb =================================================================== --- lib/tempfile.rb (revision 47655) +++ lib/tempfile.rb (revision 47656) @@ -122,7 +122,7 @@ class Tempfile < DelegateClass(File) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L122 # # 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) https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L130 @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 https://github.com/ruby/ruby/blob/trunk/lib/tempfile.rb#L347 # ... 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) Index: lib/tmpdir.rb =================================================================== --- lib/tmpdir.rb (revision 47655) +++ lib/tmpdir.rb (revision 47656) @@ -105,21 +105,12 @@ class Dir https://github.com/ruby/ruby/blob/trunk/lib/tmpdir.rb#L105 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) Index: test/test_tempfile.rb =================================================================== --- test/test_tempfile.rb (revision 47655) +++ test/test_tempfile.rb (revision 47656) @@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/test/test_tempfile.rb#L1 require 'test/unit' require 'tempfile' +require 'thread' require_relative 'ruby/envutil' class TestTempfile < Test::Unit::TestCase -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/