Ruby | Array intersection operation Last Updated : 07 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#&() is a Array class method which performs set intersection operation on the arrays. And returns the common of the two arrays. Syntax: Array.&() Parameter: Arrays for performing the intersection operation. Return: Common elements from both the arrays. Example #1 : Ruby # Ruby code for &() method # showing intersection operation # declaration of array a = [18, 22, 33, 4, 5, 6] # declaration of array b = [5, 4, 22, 1, 88, 9] # declaration of array c = [18, 22, 33, 40, 50, 6] # a intersecting b puts "intersection of a and b : #{a & b}\n\n" # a intersecting c puts "intersection of a and c : #{a & c}\n\n" # b intersecting c puts "intersection of b and c : #{b & c}\n\n" Output : intersection of a and b : [22, 4, 5] intersection of a and c : [18, 22, 33, 6] intersection of b and c : [22] Example #2 : Ruby # Ruby code for &() method # showing intersection operation # declaration of array a = ["abc", "xyz", "dog"] # declaration of array b = ["cow", "cat", "dog"] # declaration of array c = ["cat", "1", "dog"] # a intersecting b puts "intersection of a and b : #{a & b}\n\n" # a intersecting c puts "intersection of a and c : #{a & c}\n\n" # b intersecting c puts "intersection of b and c : #{b & c}\n\n" Output : intersection of a and b : ["dog"] intersection of a and c : ["dog"] intersection of b and c : ["cat", "dog"] Comment More infoAdvertise with us Next Article Ruby | Array concat() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array combination() operation Array#combination() : combination() is an Array class method which invokes with a block yielding all combinations of length 'n' of elements of the array. Syntax: Array.combination() Parameter: Arrays in which we want elements to be invoked Return: all combinations of length 'n' of elements of the ar 1 min read Ruby | Array count() operation Array#count() : count() is a Array class method which returns the number of elements in the array. It can also find the total number of a particular element in the array. Syntax: Array.count() Parameter: obj - specific element to found Return: removes all the nil values from the array. Code #1 : Exa 2 min read Ruby | Array concat() operation Array#concat() : concat() is a Array class method which returns the array after appending the two arrays together. Syntax: Array.concat() Parameter: Arrays to be combined Return: Append the two arrays Code #1 : Example for concat() method Ruby # Ruby code for concat() method # adding elements at the 2 min read Ruby | Array delete() operation Array#delete() : delete() is a Array class method which returns the array after deleting the mentioned elements. It can also delete a particular element in the array. Syntax: Array.delete() Parameter: obj - specific element to delete Return: last deleted values from the array. Code #1 : Example for 2 min read Ruby | Array at() operation Array#at() : at() is an Array class method which returns the element at the specific argumented index value. Syntax: Array.at() Parameter: - Arrays to search elements. - index to search Return: Array element at a specific index value Code #1 : Example for at() method Ruby # Ruby code for at() method 1 min read Ruby | Array delete_if() operation Array#delete_if() : delete_if() is a Array class method which deletes the arrays elements for which the block condition satisfies. Syntax: Array.delete_if() Parameter: block - condition for deleting the elements. Return: array after deleting the elements Code #1 : Example for delete_if() method Ru 1 min read Like