I like the “definition of arbitrary attributes” and I think the OpenStruct in ruby sometimes feels cleaner than using a hash, but I’m curious as to whether there are other specific advantages or use cases that make an OpenStruct a better choice than simply using a Hash.
Share
I think this mostly comes down to a performance decision. From the Ruby Documentation:
Additionally, something like a
Hashhas additional functionality with all of the methods it provides (has_key?,include?, etc.). TheOpenStructis a very simple object from that standpoint, but if you don’t have any concerns from a performance standpoint and just want an easy object to work with,OpenStructis a good choice.