[前][次][番号順一覧][スレッド一覧]

ruby-changes:14794

From: akr <ko1@a...>
Date: Sat, 13 Feb 2010 12:21:07 +0900 (JST)
Subject: [ruby-changes:14794] Ruby:r26656 (trunk): * lib/tempfile.rb (Tempfile::Remover): new class to replace

akr	2010-02-13 12:20:52 +0900 (Sat, 13 Feb 2010)

  New Revision: 26656

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26656

  Log:
    * lib/tempfile.rb (Tempfile::Remover): new class to replace
      Tempfile.callback.  port r24902 from Ruby 1.8.

  Modified files:
    trunk/ChangeLog
    trunk/lib/tempfile.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26655)
+++ ChangeLog	(revision 26656)
@@ -1,3 +1,8 @@
+Sat Feb 13 12:17:52 2010  Tanaka Akira  <akr@f...>
+
+	* lib/tempfile.rb (Tempfile::Remover): new class to replace
+	  Tempfile.callback.  port r24902 from Ruby 1.8.
+
 Fri Feb 12 17:55:21 2010  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm.c (thread_free): fixed typo.
Index: lib/tempfile.rb
===================================================================
--- lib/tempfile.rb	(revision 26655)
+++ lib/tempfile.rb	(revision 26656)
@@ -128,7 +128,7 @@
   # number of tries, then it will raise an exception.
   def initialize(basename, *rest)
     @data = []
-    @clean_proc = self.class.callback(@data)
+    @clean_proc = Remover.new(@data)
     ObjectSpace.define_finalizer(self, @clean_proc)
 
     create(basename, *rest) do |tmpname, n, opts|
@@ -230,7 +230,7 @@
       if File.exist?(@tmpname)
         File.unlink(@tmpname)
       end
-      # remove tmpname from callback
+      # remove tmpname from remover
       @data[0] = @data[2] = nil
       @data = @tmpname = nil
     rescue Errno::EACCES
@@ -257,27 +257,33 @@
   end
   alias length size
 
-  class << self
-    def callback(data)	# :nodoc:
-      pid = $$
-      Proc.new {
-	if pid == $$
-	  path, tmpfile = *data
+  # :stopdoc:
+  class Remover
+    def initialize(data)
+      @pid = $$
+      @data = data
+    end
 
-	  STDERR.print "removing ", path, "..." if $DEBUG
+    def call(*args)
+      if @pid == $$
+        path, tmpfile = *@data
 
-	  tmpfile.close if tmpfile
+        STDERR.print "removing ", path, "..." if $DEBUG
 
-	  # keep this order for thread safeness
-	  if path
-	    File.unlink(path) if File.exist?(path)
-	  end
+        tmpfile.close if tmpfile
 
-	  STDERR.print "done\n" if $DEBUG
-	end
-      }
+        # keep this order for thread safeness
+        if path
+          File.unlink(path) if File.exist?(path)
+        end
+
+        STDERR.print "done\n" if $DEBUG
+      end
     end
+  end
+  # :startdoc:
 
+  class << self
     # Creates a new Tempfile.
     #
     # If no block is given, this is a synonym for Tempfile.new.

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]