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
keys

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

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

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

2015-05-14 03:51:04
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
shift

sdbm.shift â Array or nil Instance Public methods Removes a key-value pair

2015-05-14 04:41:47
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