Skip to content
Related Articles

Related Articles

Ruby | Enumerable reject() function
  • Last Updated : 05 Dec, 2019

The reject() of enumerable is an inbuilt method in Ruby returns the items in the enumerable which does not satisfies the given condition in the block. It returns an enumerator if no block is given.

Syntax: enu.reject { |obj| block }

Parameters: The function takes a block whose condition is used to find the elements.

Return Value: It returns the items in the enum which does not satisfies the condition in the block. It returns an enumerator if no block is given.

Example #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for reject method in Enumerable
  
# Initialize 
enu = (1..10)
  
# Prints
enu.reject { |obj| obj % 2 == 1}

chevron_right


Output:

[2, 4, 6, 8, 10]

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby program for reject method in Enumerable
  
# Initialize 
enu = [1, 7, 10, 11]
  
# Prints
enu.reject

chevron_right


Output:

Enumerator: [1, 7, 10, 11]:reject
My Personal Notes arrow_drop_up
Recommended Articles
Page :