End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
GDBM#key
gdbm.key(value) → key
ext/gdbm/gdbm.c
View on GitHub ↗
static VALUE
fgdbm_key(VALUE obj, VALUE valstr)
{
struct dbmdata *dbmp;
GDBM_FILE dbm;
VALUE keystr, valstr2;
ExportStringValue(valstr);
GetDBM2(obj, dbmp, dbm);
for (keystr = rb_gdbm_firstkey(dbm); RTEST(keystr);
keystr = rb_gdbm_nextkey(dbm, keystr)) {
valstr2 = rb_gdbm_fetch2(dbm, keystr);
if (!NIL_P(valstr2) &&
(int)RSTRING_LEN(valstr) == (int)RSTRING_LEN(valstr2) &&
memcmp(RSTRING_PTR(valstr), RSTRING_PTR(valstr2),
(int)RSTRING_LEN(valstr)) == 0) {
return keystr;
}
}
return Qnil;
}
Returns the key for a given value. If several keys may map to the same value, the key that is found first will be returned.