Ruby/Development/PStore

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

create a class to represent the structure of the data

require "pstore"
class Person
  attr_accessor :name, :job, :gender, :age
end
fred = Person.new
fred.name = "F"
fred.age = 45
laura = Person.new
laura.name = "L"
laura.age = 23
 
store = PStore.new("storagefile")
store.transaction do
  store[:people] ||= Array.new
  store[:people] << fred
  store[:people] << laura
end



retrieve the data from the PStore database

require "pstore"
class Person
  attr_accessor :name, :job, :gender, :age
end
fred = Person.new
fred.name = "F"
fred.age = 45
laura = Person.new
laura.name = "L"
laura.age = 23
 
store = PStore.new("storagefile")
store.transaction do
  store[:people] ||= Array.new
  store[:people] << fred
  store[:people] << laura
end
store = PStore.new("storagefile")
people = []
store.transaction do
  people = store[:people]
end
people.each do |person|
  puts person.name
end