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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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:
... 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.