Just in case you never heard of OpenStruct…

And this is how it can be implemented…