Type:
Class
Constants:
READER : flag for #new and #open

open database as a reader

WRITER : flag for #new and #open

open database as a writer

WRCREAT : flag for #new and #open

open database as a writer; if the database does not exist, create a new one

NEWDB : flag for #new and #open

open database as a writer; overwrite any existing databases

FAST : INT2FIX(GDBM_FAST)

flag for new and open. this flag is obsolete for gdbm >= 1.8

SYNC : INT2FIX(GDBM_SYNC)

flag for new and open. only for gdbm >= 1.8

NOLOCK : INT2FIX(GDBM_NOLOCK)

flag for new and open

VERSION : rb_str_new2(gdbm_version)

version of the gdbm library

Summary

Ruby extension for GNU dbm (gdbm) – a simple database engine for storing key-value pairs on disk.

Description

GNU dbm is a library for simple databases. A database is a file that stores key-value pairs. Gdbm allows the user to store, retrieve, and delete data by key. It furthermore allows a non-sorted traversal of all key-value pairs. A gdbm database thus provides the same functionality as a hash. As with objects of the Hash class, elements can be accessed with []. Furthermore, GDBM mixes in the Enumerable module, thus providing convenient methods such as find, collect, map, etc.

A process is allowed to open several different databases at the same time. A process can open a database as a “reader” or a “writer”. Whereas a reader has only read-access to the database, a writer has read- and write-access. A database can be accessed either by any number of readers or by exactly one writer at the same time.

Examples

  1. Opening/creating a database, and filling it with some entries:

    require 'gdbm'
    
    gdbm = GDBM.new("fruitstore.db")
    gdbm["ananas"]    = "3"
    gdbm["banana"]    = "8"
    gdbm["cranberry"] = "4909"
    gdbm.close
    
  2. Reading out a database:

    require 'gdbm'
    
    gdbm = GDBM.new("fruitstore.db")
    gdbm.each_pair do |key, value|
      print "#{key}: #{value}\n"
    end
    gdbm.close
    

    produces

    banana: 8
    ananas: 3
    cranberry: 4909

Links

fastmode=

gdbm.fastmode = boolean â boolean Instance Public methods Turns the database's

2015-04-07 16:50:34
invert

gdbm.invert â hash Instance Public methods Returns a hash created by using

2015-04-07 17:05:56
length

gdbm.length â fixnum Instance Public methods Returns the number of key-value

2015-04-07 17:28:36
values_at

gdbm.values_at(key, ...) â array Instance Public methods Returns an array of

2015-04-07 18:30:34
include?

gdbm.has_key?(k) â true or falsegdbm.key?(k) â true or false Instance Public methods

2015-04-07 17:03:31
has_key?

gdbm.has_key?(k) â true or false Instance Public methods Returns true if the

2015-04-07 16:53:03
clear

gdbm.clear â gdbm Instance Public methods Removes all the key-value pairs within

2015-04-07 16:09:59
reject

gdbm.reject { |key, value| block } â hash Instance Public methods Returns a

2015-04-07 17:36:49
delete

gdbm.delete(key) â value or nil Instance Public methods Removes the key-value-pair

2015-04-07 16:24:14
keys

gdbm.keys â array Instance Public methods Returns an array of all keys of this

2015-04-07 17:22:18