End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
GDBM.open
GDBM.open(filename, mode = 0666, flags = nil)
GDBM.open(filename, mode = 0666, flags = nil) { |gdbm| ... }
ext/gdbm/gdbm.c
View on GitHub ↗
static VALUE
fgdbm_s_open(int argc, VALUE *argv, VALUE klass)
{
VALUE obj = fgdbm_s_alloc(klass);
if (NIL_P(fgdbm_initialize(argc, argv, obj))) {
return Qnil;
}
if (rb_block_given_p()) {
return rb_ensure(rb_yield, obj, fgdbm_close, obj);
}
return obj;
}
If called without a block, this is synonymous to GDBM::new. If a block is given, the new GDBM instance will be passed to the block as a parameter, and the corresponding database file will be closed after the execution of the block code has been finished.
Example for an open call with a block:
Example
require 'gdbm' GDBM.open("fruitstore.db") do |gdbm| gdbm.each_pair do |key, value| print "#{key}: #{value}\n" end end