Why when using DBM with Ruby, db[1] = 2 is ok, but print db[1] will give error?

295 Views Asked by At

On Ruby, when using DBM

require "dbm"

db = DBM.open("somedata")
db[1] = 2   # ok
p db[1]     # gives error

does anyone know db[1] = 2 is ok, but printing out db[1] will give error?

If it requires db["1"] to be valid, then how come it doesn't apply to both cases but to one case only?

1

There are 1 best solutions below

1
On BEST ANSWER

dbm convert key and value to string, so :

p db["1"]

give

"2"