We create 2 arrays. We first create an array containing integers. The array has two duplicated numbers: a 2 and a 3. We invoke the "uniq!" method, which operates in-place.
# An input array.
values = Array[4, 1, 2, 2, 3, 3]
print values,
"\n"
# Convert the array with uniq.
values.uniq!
print values,
"\n"
# A string array.
names = Array[
"cat",
"dog",
"dog",
"dog",
"mouse"]
print names,
"\n"
# Create array copy with only unique values.
unique = names.uniq
print unique,
"\n"[4, 1, 2, 2, 3, 3]
[4, 1, 2, 3]
[
"cat",
"dog",
"dog",
"dog",
"mouse"]
[
"cat",
"dog",
"mouse"]