Module: Rufus::Tokyo::Openable

Included in:
Cabinet, Dystopia::Core, Table
Defined in:
lib/rufus/tokyo/openable.rb

Overview

A mixin for classes with new() that need a matching IO-like open().

Instance Method Summary collapse

Instance Method Details

#open(*args) ⇒ Object

Same args as new(), but can take a block form that will close the db when done. Similar to File.open(). (via Zev and JEG2)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rufus/tokyo/openable.rb', line 10

def open(*args)
  db = new(*args)
  if block_given?
    begin
      yield db
    ensure
      db.close
    end
  else
    db
  end
end