From: sto.mar@...
Date: 2012-06-21T02:10:04+09:00
Subject: Re: Looking for a better way to add a method to a core class than monkey patching
Am 20.06.2012 02:23, schrieb Avdi Grimm:
> Please do not monkey patch core libraries in gems, unless the *purpose*
> of your library is to add functionality to core, eg a library of
> extensions like activesupport. Yes, this goes for additions as well as
> overrides. I cannot tell you how many times I've seen a "harmless
> addition" mess things up in confusing and hard to debug ways.
>
> What method do you want to add to strings?
Is there a way to limit the scope of an override or addition
to the namespace of the gem?
Here an example method that I use from time to time:
class String
def integer?
!!(self =~ /\A[+-]?[0-9]+\Z/)
end
end
Regards,
Marcus
--