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
[]=

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

2015-05-14 03:01:35
has_value?

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

2015-05-14 03:51:04
delete_if

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

2015-05-14 03:26:39
key?

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

2015-05-14 04:10:33
include?

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

2015-05-14 03:52:08
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
open

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

2015-05-14 02:52:52