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
length

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

2015-05-14 04:16:49
size

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

2015-05-14 04:45:35
key

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

2015-05-14 04:06:50
values_at

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

2015-05-14 05:22:30
member?

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

2015-05-14 04:20:34
closed?

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

2015-05-14 03:14:29
reject!

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

2015-05-14 04:27:54
new

SDBM.new(filename, mode = 0666) Class Public methods Creates a new database

2015-05-14 02:45:37
each_key

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

2015-05-14 03:29:41
to_a

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

2015-05-14 04:59:10