Replacing PStore

PStore is a common Ruby module which serializes objects to a file. PStore is accessed as a Hash by opening a transaction with the file. YAML.rb includes YAML::Store, a drop-in replacement for PStore.

The YAML::Store class simply needs a filename to write to when it is initialized, along with any options you like:

require 'yaml'
y = "/tmp/", :Indent => 2 )
y.transaction do
  y['names'] = ['Crispin', 'Glover']
  y['hello'] = {'hi' => 'hello', 'yes' => 'YES!!' }
Ex. 27: Initializing YAML::Store

Like PStore, the YAML::Store class can store object hierarchies, each identified by a string. The hierarchy is store in a single YAML document as a YAML mapping.

  hi: hello
  yes: YES!!
  - Crispin
  - Glover
Ex. 28: Dump of /tmp/