Implementing Array#uniq in Ruby
For one, I'd use the &lt;&lt; operator rather than push just out of convention.

Second, you still have other Array/Enumerable methods at your disposal. So there's no need to create a new array and add unique items to it. Try filtering the array instead.

Update: Whoo boy, I was still asleep when I wrote that first answer. In my defense it was early

You can actually just do

def uniq(&amp;block)
  group_by(&amp;block).values.map(&amp;:first)
end


As for my previous answer... well, I did say it could be done better. Just pretend it didn't happen.