On Sat, Jan 14, 2012 at 1:51 PM, Josh Cheek <josh.cheek / gmail.com> wrote:
> On Sat, Jan 14, 2012 at 6:06 AM, Robert Klemme
> <shortcutter / googlemail.com>wrote:
>
>>
>> It's impossible because
>>
>> =A0- you cannot change behavior of !
>>
>
> You can do this (I'm not advocating it), but IDK how you would actually
> negate it.
>
> class Regexp
> =A0def !@
> =A0 =A0/some sort of negation of #{source}/
> =A0end
> end
>
> abc =3D /abc/
> !abc # =3D> /some sort of negation of abc/

Oh, I wasn't aware of this.  Thank you for the education!

The way to use it would probably be to create a wrapper instance which
reverses semantics of the original's Regexp instance and sets global
variables accordingly (if this is possible; not sure in the case of
$1, $2 etc. because of their special nature).

Still the other obstacle would prevent making !enum.grep(/foo/) return
what is intended.  You could only do enum.grep(!/foo/).  There is a
potential though to break other code which relies on different boolean
behavior of Regexp instances so the approach with #grep_v or an
explicit Regexp#negate would be better.

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/