From: Robert Klemme Date: 2012-01-14T22:24:11+09:00 Subject: Re: negative grep On Sat, Jan 14, 2012 at 1:51 PM, Josh Cheek wrote: > On Sat, Jan 14, 2012 at 6:06 AM, Robert Klemme > wrote: > >> >> It's impossible because >> >>  - you cannot change behavior of ! >> > > You can do this (I'm not advocating it), but IDK how you would actually > negate it. > > class Regexp >  def !@ >    /some sort of negation of #{source}/ >  end > end > > abc = /abc/ > !abc # => /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 -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/