Project

General

Profile

Feature #7148

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

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

1. 1) confusing inspect

~~~ruby


t = Tempfile.new("foo") #=> #<File:/tmp/foo20121012-6762-12w11to>

t.is_a? File #=> false
~~~


2. `#dup` 2) #dup doesn't duplicate `IO`

~~~ruby
IO

t = Tempfile.new("foo")

t.dup.close

t.read #=> IOError: closed stream
~~~


3. 3) finalizer performs unlink even when it has been duplicated

~~~ruby


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()`. DelegateClass().
Therefore, I made a patch to resolve the problems.
The patched Tempfile class is a subclass of File.

Back