18 June 2014

Here is a small tip for ruby array operation

We have

a1 = ["a","b"]
a2 = ["b","c"]

Say we want to merge this two array to get a new array and it’s element must unique, you can

a3 = a1 + a2
a3.uniq!
# ["a","b","c"]

You can also do it like this

a1 | a2
# ["a","b","c"]

This is much quicker for our lazy fingers.