Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/open-temporary.rb

Constant Summary collapse

@@open =
self.method(:open)

Class Method Summary collapse

Class Method Details

.open(*argv, &block) ⇒ Object

If non-zero numbers of args are passed, works as it ought. otherwise creates and opens a temporay file.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/open-temporary.rb', line 28

def self.open(*argv, &block)
  if argv.size.nonzero?
    @@open.call(*argv, &block)
  elsif block_given?
    begin
      f = self.open_temporary
      yield f
    ensure
      f.close
    end
  else
    self.open_temporary
  end
end