The Amazing Power Of The Ruby Uniq Method

Duplicated elements!

You have an array with duplicates, but you want only unique elements.

What can you do?

Use the Array#uniq method.

It’s a method that takes your array, and by converting it to a hash, and then back to an array again, it removes all the duplicates.

Pretty cool, right?

But there is more, the “uniq” method also takes a block.

Which allows you to do more advanced things.

Wanna learn more?

I put together a new RubyGuides article for you, where you’ll find code examples & more interesting details.

This helps you write better Ruby code.

You can read the article here:

Thanks for reading & have a great day! :smiley: