Ruby refinements
From wikinotes
Refinements let you limit the scope of Monkey-Patches.
You can override methods, or add new ones, and they will only be applied to classes/modules if they are explicitly included.
Documentation
official docs https://docs.ruby-lang.org/en/3.0.0/doc/syntax/refinements_rdoc.html
Example
class User endmodule Passenger refine User def buckle_seatbelt; end end end# bind monkeypatch within this scope using Passenger # use monkeypatch user = User.new user.buckle_seatbelt