Monkey Patch Core Type (ARCH6197)
Ce contenu n’est pas encore disponible dans votre langue.
Key ruby.quality.monkey-patch-core · Severity warning · Category quality
Reopening core classes like String, Array, or Hash to add methods is fragile global mutation; it can clash with other libraries and cause surprising behaviour app-wide.
Incorrect
Section titled “Incorrect”class String def shout upcase + "!" endend
"hello".shoutCorrect
Section titled “Correct”module StringExtensions refine String do def shout upcase + "!" end endend
using StringExtensions"hello".shoutUse a helper method, a wrapper class, or a scoped refine instead of mutating the core class globally.