Am I Doing it All Wrong? Ruby Class Objects

Before you go and write custom data classes, look at the standard library OpenStruct class. They are compatible with the JSON library and hashes. (Ie, the library extends this class just as it extends others by defining the #to_json and #as_json methods.)

Class: OpenStruct (Ruby 2.5.5) (Better doc)
Class: OpenStruct (Ruby 2.7.1) (The good class introduction missing … I do not know why!)

Search on my name in this category on “OpenStruct” and you’ll find I’ve expounded upon this before.

I even wrote an example of a custom struct-like factory class: