Working with Arrays in Ruby
Another useful method while working with an array is uniq method of an Array class. It allows you to strip duplicate values from an existing array. You can also prevent an array from getting duplicates by employing to_set method of Enumerable module.
Ruby arrays use two distinct ways for deletions from an array. They are compact and delete methods.
my_array.compact //will removed nulls from the array and rearrange its index.
my_array.delete(10) //will delete all array elements equal to 10.
Reversing an array is another useful property of Ruby arrays. You can simply specify reverse method and an array will get reverse order from the original.
my_array.reverse //reverses an array
my_array.reverse! //reverses and replaces an array with new order