Array.&

Signature

array & other_array   #=> new_array

array & other_array returns new_array which contains the intersections of the two arrays. Only unique intersections will be returned. In other words, if array and/or other_array contain duplicate elements, new_array will not contain duplicate intersections.

Examples

a = [1,2,3,4,5,6,7,8,8,9,10]        #=> [1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10]
a & [0,2,4,9,11]                    #=> [2, 4, 9]
a & [0,11,22]                       #=> []
a & [0,8,8,7,6,-3]                  #=> [6, 7, 8]
a & [0,8,8,7,6,-3] & [1,2,3,4,5,6]  #=> [6]

Documentation Reference

Ruby version 1.8.6

www.ruby-doc.org : Array.&