select / reject
Selects elements matching a condition.
Syntax
arr.select { |e| condition }Description
select takes those that satisfy the condition, reject takes those that do not. filter is the same as select.
Example
Loading editor…
Expected output
[2, 4]
When to use?
Filtering the list.