Easy as a YAML Pie
YAML is a fantastic way to store data.
I already new that, but taking a refresher on through the YAML documentation, I remembered how easy it was to create an object graph and serialize it straight to YAML.Here is some code:
class Project
attr_accessor :name, :client, :people
endclass Person
attr_accessor :first_name, :last_name, :email
endAnd the YAML document:--- !ruby/object:YAML::Project
name: Build a ruby app
client: Toyota people:
- !ruby/object:YAML::Phase
email: carl@mail.com
first_name: Carl
last_name: Woodward
Now when you call Yaml.load on that you will get back a project object with all the attributes filled out and an array of people. This is a pretty nice document format. It is much easier to read then json.
Comments [0]