DEV Community


Discussion on: Thunder-Struct

databasesponge profile image
MetaDave 🇪🇺

I'm a big fan of Structs, mostly for the dot-access, but also for adding simple behaviour to the data.

I tend to use them to encapsulate lots of data items together as a single unit. For example, I have an XML export process that must be highly customisable based on the recipient, and I have a Configuration Struct that has around 20 attributes that can be accessed as:

if configuration.include_cbmc_codes?

... and which is populated from YAML.

It gives a very usable interface to the data, and is very lightweight.

Ruby 2.5 introduces keyword arguments also, making them more robust IMHO.