&

ary & other_ary â new_ary
Instance Public methods

Set Intersection â Returns a new array containing elements common to the two arrays, excluding any duplicates. The order is preserved from the original array.

It compares elements using their hash and eql? methods for efficiency.

[ 1, 1, 3, 5 ] & [ 1, 2, 3 ]                 #=> [ 1, 3 ]
[ 'a', 'b', 'b', 'z' ] & [ 'a', 'b', 'c' ]   #=> [ 'a', 'b' ]

See also #uniq.

doc_ruby_on_rails
2015-03-30 14:32:26
Comments
Leave a Comment

Please login to continue.