End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Enumerable#grep_v
grep_v(pattern) → array
grep_v(pattern) {|element| ... } → array
enum.c
View on GitHub ↗
static VALUE
enum_grep_v(VALUE obj, VALUE pat)
{
return enum_grep0(obj, pat, Qfalse);
}
Returns an array of objects based on elements of self that don’t match the given pattern.
With no block given, returns an array containing each element for which pattern === element is false:
Example
a = ['foo', 'bar', 'car', 'moo'] a.grep_v(/ar/) # => ["foo", "moo"] (1..10).grep_v(3..8) # => [1, 2, 9, 10] ['a', 'b', 0, 1].grep_v(Integer) # => ["a", "b"]
With a block given, calls the block with each non-matching element and returns an array containing each object returned by the block:
Example
a = ['foo', 'bar', 'car', 'moo'] a.grep_v(/ar/) {|element| element.upcase } # => ["FOO", "MOO"]
Related: grep.