Project

General

Profile

Actions

Feature #7148

open

Improved Tempfile w/o DelegateClass

Added by Glass_saga (Masaki Matsushita) about 12 years ago. Updated over 5 years ago.

Status:
Assigned
Target version:
-
[ruby-core:47930]

Description

I propose improved Tempfile without DelegateClass().
Present Tempfile has following problems.

  1. confusing inspect

    t = Tempfile.new("foo") #=> #<File:/tmp/foo20121012-6762-12w11to>
    t.is_a? File #=> false
    
  2. #dup doesn't duplicate IO

    t = Tempfile.new("foo")
    t.dup.close
    t.read #=> IOError: closed stream
    
  3. finalizer performs unlink even when it has been duplicated

    t = Tempfile.new("foo")
    path = t.path #=> "/tmp/foo20121012-7533-1q537gq"
    File.exist? path #=> true
    tt = t.dup
    t = nil
    GC.start
    File.exist? path #=> false
    

I think these problems caused by using DelegateClass().
Therefore, I made a patch to resolve the problems.
The patched Tempfile class is a subclass of File.


Files

patch.diff (3.52 KB) patch.diff Glass_saga (Masaki Matsushita), 10/12/2012 02:04 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #17144: Tempfile.open { ... } does not unlink the fileClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0