Suppose a regular expression comes from a call code outside the current context and then passes to another call that is implemented outside the current project:
["1", "2"].grep(/1/)
Is there a simple Ruby way to achieve the following behavior when making a call?
["1", "2"].grep(/1/.negate)
This behavior is similar to switching the operator =~ with the operator !~ . Of course, you can use #select or #reject or open or subclass Regexp . But I'm curious if there is a way already available in Ruby to deny matches returned by the regex as described above. Also, I don't care if false or nil or true , or the matching position is involved to fulfill this effect.
There is a theoretical question that matters, but that goes beyond simple considerations.
EDIT : I understand that iterators are a common way to go into Ruby to filter a list, but people ignore the limitations of the question. Also, I think there is something good functioning about how regex is upside down. I do not see it to be half excessive or too smart; it is simple object-oriented programming and what Ruby excels at the same time.
source share