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
select

sdbm.select { |key, value| ... } â Array Instance Public methods Returns a

2015-05-14 04:38:14
size

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

2015-05-14 04:45:35
reject!

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

2015-05-14 04:27:54
closed?

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

2015-05-14 03:14:29
to_a

sdbm.to_a â Array Instance Public methods Returns a new Array containing each

2015-05-14 04:59:10
key

sdbm.key(value) â key Instance Public methods Returns the key

2015-05-14 04:06:50
member?

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

2015-05-14 04:20:34
values_at

sdbm.values_at(key, ...) â Array Instance Public methods Returns an Array of

2015-05-14 05:22:30
each

sdbm.eachsdbm.each { |key, value| ... }sdbm.each_pairsdbm.each_pair { |key, value| ... } Instance

2015-05-14 03:27:25
each_key

sdbm.each_keysdbm.each_key { |key| ... } Instance Public methods Iterates

2015-05-14 03:29:41