From: Robert Dober Date: 2006-03-30T17:23:48+09:00 Subject: Re: Regexp gotcha ------=_Part_1716_8406327.1143707025367 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 3/30/06, Jacob Fugal wrote: > > On 3/29/06, Robert Dober wrote: > > (A) Somebody might rely on > > "a" =3D~ nil returning false > > in that case abandon!!! (and ask yourself why you have posted that > > question!) > > I don't think anyone's code will rely on "a" =3D~ nil returning false. > However, it's possible and even likely that someone's code will rely > on "a" =3D~ not_a_regex not raising an exception For instance, > REXML::Light::Node supports #=3D~, as mentioned in my previous post. I > wouldn't take kindly to an "extension" that breaks REXML. So you strongly oppose Rails? > (B) Matching with nil is probably a mistake that will break the code > later, > > in other words your astonishement about that behaviour will be "common > > sense", in that case the above extension of a core class is just a grea= t > > idea. > > I agree matching with nil is probably never the intended usage. > Perhaps String#=3D~ should be patched specifically to not allow nil. The > current behavior is a side effect of nil being an Object and thus > inheriting Object#=3D~. > > However, I disagree with the sweeping "extension" whereby anything > that's not a Regexp causes String#=3D~ 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 am however open for discussion if that power of ruby shall be "removed", "restricted" or kept. I think that -w could do things about it or SAVE levels. Probably worth a different thread. But I am not Matz :( Cheers Robert > > -- Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_1716_8406327.1143707025367--