January 2024
Intermediate to advanced
718 pages
20h 15m
English
Class Tempfile creates managed temporary files. Although they behave the same as any other IO objects, temporary files are automatically deleted when the Ruby program terminates. Once a Tempfile object has been created, the underlying file may be opened and closed a number of times in succession.
Tempfile doesn’t directly inherit from IO. Instead, it delegates calls to a File object. From the programmer’s perspective, apart from the unusual new, open, and close semantics, a Tempfile object behaves as if it were an IO object.
If you don’t specify a directory to hold temporary files when you create them, the Dir.tmpdir location will be used to find a system-dependent location. Here’s an example:
| | require "tempfile" ... |
Read now
Unlock full access