User defined function, recursion and passing self along

I’m not sure what static typing has to do with this situation. I think of that wtf as a mutability issue. If you use the non-bang version of uniq you’ll find the result less confusing. I’ve found myself avoiding bang methods in Ruby more and more as my experience grows.

irb(main):001:0> a = [1,2,3,3,4,5]
=> [1, 2, 3, 3, 4, 5]
irb(main):002:0> b = [1,2,3,4,5]
=> [1, 2, 3, 4, 5]
irb(main):003:0> a.uniq
=> [1, 2, 3, 4, 5]
irb(main):004:0> b.uniq
=> [1, 2, 3, 4, 5]
irb(main):005:0> a.uniq!
=> [1, 2, 3, 4, 5]
irb(main):006:0> b.uniq!
=> nil
irb(main):007:0> a
=> [1, 2, 3, 4, 5]
irb(main):008:0> b
=> [1, 2, 3, 4, 5]
irb(main):009:0>

uniq! modifies the array in place and returns the modified version or else it’s already unique and it returns nil to indicate that. It’s a horribly confusing method. uniq just returns a new array with unique elements.