diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-01-19 05:08:25 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-01-19 05:08:25 +0000 |
commit | 5c47ddf9e7fa05bc993818c166e8162c20a970f9 (patch) | |
tree | 2f6b7ca53886b3e41a06d1268fb65e0a7bfbe741 /lib/tempfile.rb | |
parent | d556e58fc0f5d94961e4ecb765cb1052cd754871 (diff) |
Mon Jan 19 14:06:13 JST 1998
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@23 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/tempfile.rb')
-rw-r--r-- | lib/tempfile.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb index a6ffaa55fe..93869aebbc 100644 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -6,11 +6,11 @@ # The class for temporary files. # o creates a temporary file, which name is "basename.pid.n" with mode "w+". # o Tempfile objects can be used like IO object. -# o created temporary files are removed if it is closed or garbage collected, -# or script termination. +# o created temporary files are removed on closing or script termination. # o file mode of the temporary files are 0600. require 'delegate' +require 'final' class Tempfile < SimpleDelegater Max_try = 10 @@ -45,8 +45,7 @@ class Tempfile < SimpleDelegater File.unlink(@tmpdir + '/' + @tmpname + '.lock') end } - ObjectSpace.call_finalizer(self) - ObjectSpace.add_finalizer(@clean_files) + ObjectSpace.define_finalizer(self, @clean_files) @tmpfile = open(@tmpname, 'w+') super(@tmpfile) @@ -57,8 +56,13 @@ class Tempfile < SimpleDelegater end end + def Tempfile.open(*args) + Tempfile.new(*args) + end + def close - super + @tmpfile.close @clean_files.call + ObjectSpace.undefine_finalizer(self) end end |