Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Enumerable#reject

enum.reject { |obj| block } → array
enum.reject → an_enumerator

Returns an array for all elements of enum for which the given block returns false.

If no block is given, an Enumerator is returned instead.

Example
(1..10).reject { |i|  i % 3 == 0 }   #=> [1, 2, 4, 5, 7, 8, 10]

[1, 2, 3, 4, 5].reject { |num| num.even? } #=> [1, 3, 5]

See also Enumerable#find_all.

See also #reduce #reverse_each #partition #select also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1