« Back to Index

Ruby Array subset methods (intersection, difference, union)

View original Gist on GitHub

Example.rb

trello = ["a", "b", "c"]
jira   = ["d", "c", "e"]

# - is the difference
# & is the intersection
# | is the union

trello - jira # ["a", "b"]                -> a and b exist in trello but not jira
trello & jira # ["c"]                     -> c exists in both trello and jira
trello | jira # ["a", "b", "c", "d", "e"] -> both arrays have been joined