From: Jacob Fugal Date: 2006-03-31T02:13:22+09:00 Subject: Re: Regexp gotcha On 3/30/06, Robert Dober wrote: > On 3/30/06, Jacob Fugal wrote: > > I don't think anyone's code will rely on "a" =~ nil returning false. > > However, it's possible and even likely that someone's code will rely > > on "a" =~ not_a_regex not raising an exception For instance, > > REXML::Light::Node supports #=~, as mentioned in my previous post. I > > wouldn't take kindly to an "extension" that breaks REXML. > > So you strongly oppose Rails? I wasn't aware Rails (or probably more particularly, ActiveSupport) broke REXML. If so, then yes I'd strongly oppose that particular extension within ActiveSupport/Rails that breaks REXML. > > However, I disagree with the sweeping "extension" whereby anything > > that's not a Regexp causes String#=~ to raise an exception. I take > > this as an example of how tricky it can be to *safely* "extend" the > > core modules. This doesn't mean you can't do it, just that you should > > be *very careful. > > That was just a toy extension to pass the idea of what ruby can do to the > poster. Than I found myself mildly attacked about the extension stuff, so I got > mildely defensive. It is *not* fair to judge the whole idea of extending or not extending > core objects by a simple example that was written to show the power of ruby. I understand that. I just thought it a good opportunity to point out how easy it is to make mistakes like this. I make them all the time as well. I was not judging the general idea of extending core objects -- I, like you, would be very put out if the power were removed. I like to play/use it and I've seen some very nifty and useful things done with it. I was just pointing out how easy it is to break other people's code if you extend core classes without being careful. And don't worry, we weren't attacking you or your coding ability by pointing out the flaws in the code you proposed as an example. Just trying to make sure the bases were covered. Please keep experimenting and posting your ideas; and when you find flaws in my code, enlighten me please! :) Jacob Fugal