Union, Difference and Intersect with Ruby Arrays
Union
> [:a, :b, :c].union([:b, :c, :d])
=> [:a, :b, :c, :d]
# or
> [:a, :b, :c] | [:b, :c, :d]
=> [:a, :b, :c, :d]
“Union all” / Concat
[:a, :b].concat([:b, :c])
=> [:a, :b, :b, :c]
# or
[:a, :b] + [:b, :c]
=> [:a, :b, :b, :c]
Difference
> [:a, :b, :c].difference([:b, :c, :d])
=> [:a]
# or
[:a, :b, :c] - [:b, :c, :d]
=> [:a]
Intersect
> [:a, :b, :c] & [:b, :c, :d]
=> [:b, :c]