Sha256: afaa9bc0cfcaad1a41ab21cdb8a832b7ec2f109847d26bdb8ba1a9b9f91760e4

Contents?: true

Size: 458 Bytes

Versions: 6

Compression:

Stored size: 458 Bytes

Contents

module Rufus::Tokyo
  #
  # A mixin for classes with new() that need a matching IO-like open().
  #
  module Openable
    #
    # 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)
    #
    def open(*args)
      db = new(*args)
      if block_given?
        begin
          yield db
        ensure
          db.close
        end
      else
        db
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rufus-tokyo-1.0.7 lib/rufus/tokyo/openable.rb
rufus-tokyo-1.0.6 lib/rufus/tokyo/openable.rb
rufus-tokyo-1.0.5 lib/rufus/tokyo/openable.rb
rufus-tokyo-1.0.4 lib/rufus/tokyo/openable.rb
rufus-tokyo-1.0.3 lib/rufus/tokyo/openable.rb
rufus-tokyo-1.0.2 lib/rufus/tokyo/openable.rb