Created
November 18, 2018 11:24
-
-
Save astrophysik928/b449e5c2c21231814c08998b0f2d0a99 to your computer and use it in GitHub Desktop.
PStoreにデータ書き込み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'pstore' | |
# PStoreデータベースを作成する。なければ自動的に作成される。 | |
db = PStore.new('drinkdb') | |
# PStoreにデータを書き込む | |
db.transaction do | |
# 文字列をキーを指定してPStoreに保存する | |
db["somethingToDrink"] = "orange juice" | |
# 文字列をキーを指定してPStoreに保存する | |
db["somethingToEat"] = "ramen" | |
end | |
# transactionメソッドを抜けた後に、PStoreに書き込まれる。 | |
# PStoreからデータを読み込んで表示する。transactionメソッドは「true」を指定すると読み込みモードになる。 | |
db.transaction(true) do | |
puts db["somethingToDrink"] | |
puts db["somethingToEat"] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment