?? 05 - using berkeley db databases.rb
字號:
require 'dbm'DBM.open('random_thoughts') do |db| db['tape measure'] = "What if there was a tape measure you could use as a yo-yo?" db[23] = "Fnord."endDBM.open('random_thoughts') do |db| puts db['tape measure'] puts db['23']end# What if there was a tape measure you could use as a yo-yo?# Fnord.DBM.open('random_thoughts') { |db| db[23] }# TypeError: can't convert Fixnum into StringDir['random_thoughts.*']# => ["random_thoughts.pag", "random_thoughts.dir"]#---require 'bdb'db = BDB::Hash.create('random_thoughts2.db', nil, BDB::CREATE) db['Why do we park on a driveway but'] = 'it never rains but it pours.'db.closedb = BDB::Hash.open('random_thoughts2.db', nil, 'r')db['Why do we park on a driveway but']# => "it never rains but it pours."db.close#---db = BDB::Btree.create('element_reviews.db', nil, BDB::CREATE) db['earth'] = 'My personal favorite element.'db['water'] = 'An oldie but a goodie.'db['air'] = 'A good weekend element when you're bored with other elements.'db['fire'] = 'Perhaps the most overrated element.'db.each { |k,v| puts k }# air# earth# fire# waterdb['water'] # => "An oldie but a goodie."db.close#---
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -