似乎如果我在 Ruby 上使用 Berkeley DB (DBM),哈希的键和值必须是字符串?它们可以是其他数据类型吗?
require 'dbm'
d = DBM.open('test1')
d[1] = 2
d[123] = 456
d[2] = 2.34
d['wa'] = Time.now.to_f
p d.keys
p d.values
结果:
C:\>ruby test_dbm.rb
["wa", "2", "1", "123"]
["1259229787.686", "2.34", "2", "456"]