Dual-purpose modules: refinements or global patches

suggest change

Scope 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents