require "pstore"

# Assume existing file with two objects stored

store = PStore.new("objects")
store.transaction do |s|
  a = s["my_array"]
  h = s["my_hash"]
  # Imaginary code omitted, manipulating
  # a, h, etc.
  # Assume a variable named "condition" having
  # the value 1, 2, or 3...
  case condition
    when 1
      puts "Oops... aborting."
      s.abort    # Changes will be lost.
    when 2
      puts "Committing and jumping out."
      s.commit # Changes will be saved.
    when 3
      # Do nothing...
  end
  puts "We finished the transaction to the end."
  # Changes will be saved.
end

