Dual-purpose modules: refinements or global patches
suggest changeScope a patch with a refinement, and also include it when you want the methods everywhere (for example in development or testing).
using activates a refinement only in the lexical scope where it appears (a file, class, or module). It does not change String for the rest of the process. include inside refine was removed in Ruby 3.2; import the methods instead:
module Patch
def patched?; true; end
refine String do
import_methods Patch
end
end
# everywhere
String.include Patch
"".patched? # => true
# this scope only
class LoadPatch
using Patch
"".patched? # => true
end
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents