Storing Objects in YAML with Ruby

Jordan Moore
Launch School
Published in
9 min readAug 13, 2019

--

Anyone who has used Ruby has most likely internalized one truth:

Everything in Ruby is an object.

These are objects according to Ruby.

This truth is inescapable, undeniable, and persistent. Ruby’s ability to store anything as an object is immensely powerful.

However, when writing to different file types from within Ruby, how can we store the objects created in our program and access them later?

Let’s say we had a .txt file, and we wrote to it from within our Ruby program. How could we store an object in that file?

One method for storing objects from Ruby is to use a YAML file.

YAML stands for “YAML Ain’t Markup Language”, and is a human friendly data serialization standard for all programming languages. We can use YAML files in conjunction with our Ruby program to store objects, and in the case of web browsing, maintain state by storing data that persists in external files. Additionally, by overwriting YAML files, we can modify the values inside of our stored Ruby objects.

Installing the Project(s) and Dependencies

Download the following projects from Github:

1. Incomplete Project (used for following tutorial)
2. Complete Project (used for checking results, optional)

--

--