Ruby refinements: Difference between revisions
From wikinotes
(Created page with "Refinements let you limit the scope of Monkey-Patches.<br> You can override methods, or add new ones, and they will only be applied to classes/modules if they are explicitly i...") |
(No difference)
|
Revision as of 01:53, 19 November 2021
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