Rails 6 has made
many new additions to Array and Enumerable:
Array#excluding and Enumerable#excluding
There are times when we would like to remove an element from a collection.
On Array or Enumerable, we could achieve this by collectionA - collectionB.
Rails offers a more readable approach to these via Array#without and Enumerable#without
With the introduction of its counterparts #including,
we can now perform this same functionality as #excluding
With this addition, it also fixes an issue
where the exclusion would fail if we passed an Array.
We can also successfully pass collections to be excluded now.
The without method is still available and is an alias to excluding.
Array#including and Enumerable#including
To match their counterparts #excluding we can now
perform #including on Array and Enumerable.
This is a shorthand and more readable form of
addition of two collections.
As we can see, #including and #excluding add an easier and more readable way to
work with collection addition and removals.