On Fri, Jan 13, 2012 at 7:01 PM, Peter Vandenabeele
<peter / vandenabeele.com> wrote:

> It took me quite some time to grasp that the '-i' and '-v' options of
> $ grep =A0-i
> $ grep -v
> do something very different ...
>
> '-i' changes the behavior of the Regexp _itself_
>
> '-v' changes the behavior of the filter on the lines, _after_ the regexp =
is
> calculated
> (changes it from "ruby select" to "ruby reject")
>
> So, I believe now that my earlier proposal of a Ruby regexp like /.../v d=
oes
> not make a lot of sense in this context.

I think it could be done but there would be some odd effects:

 - Match ($&) would always be the whole string (regexp doesn't match)
or nil (regexp matches).
 - capturing groups would never be set
 - a lot of generic code which relies on regexps to positively match
could be broken if handed a /v regexp

All in all I'd say it's probably not such a good idea. :-)
> Negation could be an option for the Enumerable grep command, but that
> is probably more complex than just implementing the grep_v you suggested.

It's impossible because

 - you cannot change behavior of !
 - even if you could, at the moment when ! (or any other negation)
should take place the information needed to calculate the result (i.e.
the entries filtered out) is no longer accessible (it has been
filtered out).

Kind regards

robert

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