End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
GDBM#select
gdbm.select { |key, value| block } → array
ext/gdbm/gdbm.c
View on GitHub ↗
static VALUE
fgdbm_select(VALUE obj)
{
VALUE new = rb_ary_new();
GDBM_FILE dbm;
struct dbmdata *dbmp;
VALUE keystr;
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
VALUE assoc = rb_assoc_new(keystr, rb_gdbm_fetch2(dbm, keystr));
VALUE v = rb_yield(assoc);
if (RTEST(v)) {
rb_ary_push(new, assoc);
}
GetDBM2(obj, dbmp, dbm);
}
return new;
}
Returns a new array of all key-value pairs of the database for which block evaluates to true.