filter

.filter() { |element| ... }

Yields each element in this array into the attached block. If the block returns true, then the element is kept, and otherwise it will be removed.

Note that this returns the changes in a new array.

ns = [ 10, 20, 30, 60, 70, 80 ]

// keep all values less than 50
ns.filter() { |n| return n < 50 }

See also

deleteIf