Ruby question: In preparation to a Rails 7 upgrad...
# support
t
Ruby question: In preparation to a Rails 7 upgrade I am currently rewriting some monkey patches from
Module.module_eval
into
Module#prepend
. So they work with the new zeitwerk auto loader. [Due to a "bug" in Ruby 2.7](https://github.com/jruby/jruby/issues/6445#issuecomment-894407106) prepended modules of modules included in classes do not get prepended to the class, leading to not overwritten methods as one would expect using
Module#prepend
with modules prepended into classes. I have several ideas to circumvent the issue 1. Prepend the module into the class the module that the monkey patch was meant for. Problem with this is that the module in question (
Spree::Core::ControllerHelpers::Order
) is included in several controllers and I would like to not maintain a list of controllers that I need to prepend my module in to. 2. Use
module_eval
in the
prepended
hook. Just an idea I have, that I have not tried yet. 3. Trick Zeitwerk by adding the constant it expects from the file name and keep the existing
module_eval
Feels fishy 4. Use a folder that is excluded from Zeitwerk auto loading. Not very convenient during development locally. Has anybody run into these kind of issues before and solved it? If yes, how?
I went with 2.) use
module_eval
in the
self.prepended
hook. Works pretty well so far.
party parrot 2