Skip to content

Monkey Patch Core Type (ARCH6197)

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.

class String
def shout
upcase + "!"
end
end
"hello".shout
module StringExtensions
refine String do
def shout
upcase + "!"
end
end
end
using StringExtensions
"hello".shout

Use a helper method, a wrapper class, or a scoped refine instead of mutating the core class globally.