Hi --

On Thu, 30 Mar 2006, Pistos Christou wrote:

> Robert Dober wrote:
>> class String
>>     alias_method :__old_match, :=~
>>     def =~(obj)
>>         raise RuntimeError,
>>                "#{obj.nil? ? "nil" : obj.to_s} is not a Regexp but #{
>> obj.class}" unless Regexp === obj
>>         __old_match obj
>>     end # def =~(obj)
>> end # class String
>
> Thanks for the suggestion, Robert.
>
> While I have no qualms about extending core classes, this sort of
> adjustment feels like too... "brash"? of a modification for me.  :)

You should have *some* qualms :-)  But in any case, this change is
certainly one I wouldn't make.  I have no way of knowing whether
someone has done this somewhere:

   if str =~ re

and not tested for re being nil because it doesn't affect the outcome
of the test.


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black