Persistent Data in .rb
Functions to save and load game data with native Marshal file management in Ruby

Persistent Data in .rb

I was hesitant to develop this feature. Fundamentally, a player should be able to save a beloved game, perhaps juggle a couple of different options, and then return to them at a later time. Would this require a massive backend database? Some sort of complicated system to parse data into strings and strings back into data?

Yet after researching several options, the native Marshal file system in Ruby is incredibly friendly for developers. With only a couple lines of code, Ruby transforms a couple of objects into a hash and writes that into a .marshal file. The process is just as easy to reverse, and keeps the user interaction within the terminal.

This update also provides a menu system with options to continue playing, start a new game, save the game, load a game, or quit back to the terminal. Future updates will look at alternatives to global variables and provide user-selection of seed values.

Codebase


Marshal documentation

Benchmark data

I love seeing this progress! Such a cool project

Like
Reply

Awesome job! Looking forward to more updates as you continue to build on this project!

Like
Reply

To view or add a comment, sign in

More articles by Christopher Aument

  • Project-based Learning

    What is continuous learning? It's more than just a buzzword. Reading documentation, studying books and papers, and…

  • 100% Test Coverage

    It's not about the destination, it's about the journey. I'm not a fan of testing.

    3 Comments
  • Procedural generation in Ruby

    For a first foray into project development in Ruby, Tammy Tran and Ira Holmes worked with me to develop a text-based…

    3 Comments

Explore content categories