Skip to content

Instantly share code, notes, and snippets.

@zhengjia
Created June 1, 2010 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhengjia/421413 to your computer and use it in GitHub Desktop.
Save zhengjia/421413 to your computer and use it in GitHub Desktop.
array include
#You can just use a set difference (aka minus) to see if one array includes all elements of another
not_included = [1,2,3] - (1..9).to_a
not_included # => []
not_included = [1,2,3,'A'] - (1..9).to_a
not_included # => ["A"]
#Use intersection to test if any of the one are in the other:
shared = [1,2,3,'A'] & (1..9).to_a
shared # => [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment