Ruby | Array uniq!() function Last Updated : 06 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#uniq!() : uniq!() is a Array class method which removes duplicate elements from the array and returns only if there is duplicate element in the array. Syntax: Array.uniq!() Parameter: Array Return: removes duplicate elements from the array. Example #1 : Ruby # Ruby code for uniq!() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 50, 6] # uniq! method example puts "uniq!() method form : #{a.uniq!()}\n\n" puts "uniq!() method form : #{b.uniq!()}\n\n" puts "uniq!() method form : #{c.uniq!()}\n\n" Output : uniq!() method form : uniq!() method form : [1, 4, 88, 9] uniq!() method form : Example #2 : Ruby # Ruby code for uniq!() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil, "cat"] # declaring array b = ["cow", nil, "dog"] # uniq! method example puts "uniq!() method form : #{a.uniq!()}\n\n" puts "uniq!() method form : #{b.uniq!()}\n\n" puts "uniq!() method form : #{c.uniq!()}\n\n" Output : uniq!() method form : uniq!() method form : uniq!() method form : ["cat", nil] Comment More infoAdvertise with us Next Article Ruby | Array zip() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Array-class Similar Reads Ruby | Array uniq() function Array#uniq() : uniq() is a Array class method which returns a new array by removing duplicate values in the array. Syntax: Array.uniq() Parameter: Array Return: a new array by removing duplicate values in the array Example #1 : Ruby # Ruby code for uniq() method # declaring array a = [18, 22, 33, ni 2 min read Ruby | Array unshift() function Array#unshift() : unshift() is a Array class method which returns the shifted array with argumented element in place. Syntax: Array.unshift()Parameter: ArrayReturn: the shifted array with argumented element in place. Example #1 : Ruby # Ruby code for unshift() method # declaring array a = [18, 22, 3 2 min read Ruby | Array zip() function Array#zip() : zip() is a Array class method which Converts any arguments to arrays, then merges elements of self with corresponding elements from each argument. Syntax: Array.zip() Parameter: Array Return: merges elements of self with corresponding elements from each argument. Example #1 : Ruby # Ru 2 min read Ruby | Array slice!() function Array#slice!() : slice!() is a Array class method which seletes the element(s) given by an index or by a range. Syntax: Array.slice!() Parameter: Array Return: Deletes the elements given by an index or by a range. Example #1 : Ruby # Ruby code for slice!() method # declaring array a = [18, 22, 33, n 2 min read Ruby | Array shift() function Array#shift() : shift() is a Array class method which removes the first element of self and returns it or nil if the array is empty. Syntax: Array.shift() Parameter: Array Return: removes the first element of self and returns it or nil if the array is empty. Example #1 : Ruby # Ruby code for shift() 2 min read Ruby | Array sort!() function Array#sort!() : sort!() is a Array class method which returns sorted self array in place. Syntax: Array.sort!() Parameter: Array Return: sorted self array in place. Example #1 : Ruby # Ruby code for sort!() method # declaring array a = ["abc", "nil", "dog"] # declaring 1 min read Like