I’m developing a Gem which I think will be useful for more people than just me. One issue I’m facing is that I need to merge nested hashes. I found this useful Gist to accomplish that, but now I’m wondering if it’s okay to modify Hash# like this in a Gem?
I’m sure there’s a community “standard” or best practices that either accepts or declines this sort of code, so I’m turning to SO for guidance.
Thank you.
When in doubt, just subclass
Hashand include the Module in your subclass. You should particularly do this, when you override methods or change the behavior dramatically.But i don’t see why you shouldn’t just modify the
Hashclass. Rails, for example, extends Core classes rigorously and i’ve never heard someone complain. You might take a look at how Rails’activesupportextends core classes:https://github.com/rails/rails/tree/master/activesupport/lib/active_support/core_ext
Just make sure not to break existing behavior, so the users of your gem will not experience unwanted side-effects.