instance method Array#uniq

View source on GitHub →

Array#uniq([sorted = false]) → Array
  • sorted (Boolean) – Whether the array has already been sorted. If true, a less-costly algorithm will be used.

Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned.

On large arrays when sorted is false, this method has a potentially large performance cost.

[1, 3, 2, 1].uniq();
// -> [1, 2, 3]
 ['A', 'a'].uniq();
// -> ['A', 'a'] (because String comparison is case-sensitive)