Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Ruby | Enumerable grep_v() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The grep_v() of enumerable is an inbuilt method in Ruby returns an array of elements which contain every (element != pattern). If the optional block is not given, then it returns an array which does not contain the elements in that pattern.

Syntax: enu.grep_v(pattern) { |obj| block }

Parameters: The function takes a pattern and an optional block.

Return Value: It returns either an array of boolean values or an array containing the elements that are not contained in the pattern.

Example #1:




# Ruby program for grep_v method in Enumerable
  
# Initialize 
enu = (1..10)
  
# Prints
enu.grep_v (3..5)

Output:

[1, 2, 6, 7, 8, 9, 10]

Example #2:




# Ruby program for grep_v method in Enumerable
  
# Initialize 
enu = (1..10)
  
# Prints
enu.grep_v (3..5) { |obj| obj + 10 }

Output:

[11, 12, 16, 17, 18, 19, 20]
My Personal Notes arrow_drop_up
Last Updated : 05 Dec, 2019
Like Article
Save Article
Similar Reads