recursive-open-struct
recursive-open-struct copied to clipboard
Fix Ruby 3.1 #freeze
Fixes #74.
I played around with the first solution I proposed there, i.e. defining all methods during the initialization by using super, but there are some behaviors of RecursiveOpenStruct that were too specific to make it work, like the preserve_original_keys option. The original implementation simply converts every key to a Symbol.
So I went with the second option: override Object#freeze to create all methods before freezing the object itself.
The gem could also provide a #deep_freeze that would freeze the object, as well as all its sub-elements, recursively.