Type:
Class

SDBM provides a simple file-based key-value store, which can only store String keys and values.

Note that Ruby comes with the source code for SDBM, while the DBM and GDBM standard libraries rely on external libraries and headers.

Examples

Insert values:

require 'sdbm'

SDBM.open 'my_database' do |db|
  db['apple'] = 'fruit'
  db['pear'] = 'fruit'
  db['carrot'] = 'vegetable'
  db['tomato'] = 'vegetable'
end

Bulk update:

require 'sdbm'

SDBM.open 'my_database' do |db|
  db.update('peach' => 'fruit', 'tomato' => 'fruit')
end

Retrieve values:

require 'sdbm'

SDBM.open 'my_database' do |db|
  db.each do |key, value|
    puts "Key: #{key}, Value: #{value}"
  end
end

Outputs:

Key: apple, Value: fruit
Key: pear, Value: fruit
Key: carrot, Value: vegetable
Key: peach, Value: fruit
Key: tomato, Value: fruit
clear

sdbm.clear â self Instance Public methods Deletes all data from the database

2015-05-14 03:05:42
close

sdbm.close â nil Instance Public methods Closes the database file.

2015-05-14 03:10:06
store

sdbm.store(key, value) â value Instance Public methods Stores a new value

2015-05-14 04:51:41
open

SDBM.open(filename, mode = 0666)SDBM.open(filename, mode = 0666) { |sdbm| ... } Class Public methods

2015-05-14 02:52:52
include?

sdbm.include?(key) â true or false Instance Public methods Returns true

2015-05-14 03:52:08
length

sdbm.length â integer Instance Public methods Returns the number of keys in

2015-05-14 04:16:49
value?

sdbm.value?(key) â true or false Instance Public methods Returns true

2015-05-14 05:09:42
reject

sdbm.reject { |key, value| ... } â Hash Instance Public methods Creates a new

2015-05-14 04:22:07
invert

sdbm.invert â Hash Instance Public methods Returns a

2015-05-14 03:59:15
to_hash

sdbm.to_hash â Hash Instance Public methods Returns a new

2015-05-14 05:02:36