uniq で重複要素を取り除く。例えば
phone = [0, 2, 3, 4, 4, 1, 1, 1, 1, 1]ならば changed = phone.uniq changed = [0, 2, 3, 4, 1] phone は変わらず phone.uniq! ならば phone = [0, 2, 3, 4, 1]
である。試してみよう。
> phone = [0, 2, 3, 4, 4, 1, 1, 1, 1, 1] => [0, 2, 3, 4, 4, 1, 1, 1, 1, 1] > phone.uniq => [0, 2, 3, 4, 1] > phone => [0, 2, 3, 4, 4, 1, 1, 1, 1, 1] > phone.uniq! => [0, 2, 3, 4, 1] > phone => [0, 2, 3, 4, 1]
! は破壊的 method を意味し、もとの定義を変更してしまう。