Exclude Values From An Array
In true Ruby fashion, there are all sorts of ways to exclude values from an array.
If you just want to exclude nil
values, you can use #compact
.
If you want to exclude nil
values and some other named value, you could use #filter
or #reject
.
The filter is clumsy and heavy-handed for this sort of example. A really terse way of doing the same thing is with set difference: #-
.
Or the spelled out #difference
method.
Last updated