Class: Tempfile

Inherits:
Object show all
Defined in:
lib/keystone/core_ext/tempfile.rb

Class Method Summary collapse

Class Method Details

.open_with_block(name = nil, dir = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/keystone/core_ext/tempfile.rb', line 5

def self.open_with_block(name = nil, dir = nil)
  name ||= (0..8).map{rand(36).to_s(36)}.join
  args = dir ? [name, dir] : [name]
  tmp = Tempfile.open *args
  begin
    yield tmp
  ensure
    tmp.close true
  end
end