# /app/foo.rb

class Foo
  attr_accessor :title, :body
end
# /app/app.rb

require 'foo'
require 'yaml'

foo = Foo.new
foo.title = 'Foo Bar'
foo.body = 'Bar Baz'

puts YAML.dump(foo)

foo_yaml = YAML.dump(foo)

copy = YAML.load(foo_yaml)

puts copy.title

YAML::Store

require 'yaml/store'

class Post
  attr_accessor :title, :body, :id
end

post = Post.new
post.title = 'Foo'
post.body = 'Bar'
post.id = 1

store = YAML::Store.new('foo.yaml')

# write
store.transaction do
  store["First post"] = post
end

# read
store.transaction do
  puts store["First post"].title
end

# получить ключи в виде массива
store.transaction do
  p store.roots
end

Посмотреть пример использования и реализации в приложении Sinatra: https://github.com/krdprog/hfr-sinatra