Ruby | Array &() function Last Updated : 05 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#&() : &() is an Array class method which returns a new array containing unique elements common to the two arrays. Syntax: Array.&() Parameter: Array for the comparison Return: a new array containing unique elements common to the two arrays Example #1 : Ruby # Ruby code for &() method # declaring arrays a = [18, 22, 33, 4, 5, 6] # declaring arrays b = [18, 22, 33, 4, 5, 6] # declaring arrays c = [18, 22, 33, 40, 50, 6] # & method puts "& method form : #{a & b}\n\n" # & method puts "& method form : #{a & c}\n\n" # & method puts "& method form : #{b & c}\n\n" Output : & method form : [18, 22, 33, 4, 5, 6] & method form : [18, 22, 33, 6] & method form : [18, 22, 33, 6] Example #2 : Ruby # Ruby code for &() method # declaring arrays a = ["abc", "xyz", "dog"] # declaring arrays b = ["cat", "cat", "dog"] # declaring arrays c = ["cat", "cat", "dog"] # & method puts "& method form : #{a & b}\n\n" # & method puts "& method form : #{a & c}\n\n" # & method puts "& method form : #{b & c}\n\n" Output : & method form : ["dog"] & method form : ["dog"] & method form : ["cat", "dog"] Comment More infoAdvertise with us Next Article Ruby | Array &() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array append() function Array#append() is an Array class method which add elements at the end of the array. Syntax: Array.append() Parameter: - Arrays for adding elements. - elements to add Return: Array after adding the elements at the end. Example #1 : Ruby # Ruby code for append() method # adding elements at the end # d 2 min read Ruby | Array to_a() function Array#to_a() : to_a() is a Array class method which returns self array. Syntax: Array.to_a() Parameter: Array Return: self array representation Example #1 : Ruby # Ruby code for to_a() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c 1 min read Ruby | Array map() function Array#map() : map() is a Array class method which returns a new array containing the values returned by the block. Syntax: Array.map() Parameter: Array Return: a new array containing the values returned by the block. Example #1 : Ruby # Ruby code for map() method # declaring array a = [18, 22, 33, 3 2 min read Ruby | Array one?() function Array#one?() : one?() is a Array class method which checks whether the array is having only one array element. Syntax: Array.one?() Parameter: Array Return: true - if array has only one element otherwise return false. Example #1 :Â Ruby # Ruby code for one?() method # declaring array a = [18, 22, 33 1 min read Ruby | Array pop() function Array#pop() : pop() is a Array class method which checks removes the last element from the array and returns it. Syntax: Array.pop() Parameter: Array Return: removes the last element from the array and returns it. Example #1 : Ruby # Ruby code for pop() method # declaring array a = [18, 22, 33, nil, 1 min read Like