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
has_value?

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

2015-05-14 03:51:04
keys

sdbm.keys â Array Instance Public methods Returns a new Array containing the

2015-05-14 04:15:36
key?

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

2015-05-14 04:10:33
[]=

sdbm[key] = value â value Instance Public methods Stores a new value

2015-05-14 03:01:35
delete_if

sdbm.delete_if { |key, value| ... } â self Instance Public methods Iterates

2015-05-14 03:26:39
each_value

sdbm.each_valuesdbm.each_value { |value| ... } Instance Public methods Iterates

2015-05-14 03:35:43
replace

sdbm.replace(pairs) â self Instance Public methods Empties the database, then

2015-05-14 04:32:43
update

sdbm.update(pairs) â self Instance Public methods Insert or update key-value

2015-05-14 05:04:56
empty?

sdbm.empty? â true or false Instance Public methods Returns true

2015-05-14 03:43:01
clear

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

2015-05-14 03:05:42