aetherknight / recursive-open-struct

OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
Other
276 stars 54 forks source link

Fix Ruby 3.1 #freeze #75

Closed Richard-Degenne closed 2 months ago

Richard-Degenne commented 1 year ago

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.

aetherknight commented 2 months ago

LGTM, apologies on the delay for getting this reviewed and added.