Module: Arrow::BlockClosable

Defined in:
lib/arrow/block-closable.rb

Instance Method Summary collapse

Instance Method Details

#open(*args, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/arrow/block-closable.rb', line 20

def open(*args, &block)
  io = new(*args)
  return io unless block

  begin
    yield(io)
  ensure
    if io.respond_to?(:closed?)
      io.close unless io.closed?
    else
      io.close
    end
  end
end