Ruby allows you to use public instance methods for two arrays to get their intersecting or exclusive elements:
a1 = ['alpha', 'bravo', 'charlie', 'delta', 'echo'] a2 = ['charlie', 'echo'] puts a1 - a2 => ['alpha', 'bravo', 'delta'] puts a1 & a2 => ['charlie', 'echo']
Check out the Rubydoc Array for more information. It is likely that you will find exactly what you need there.
source share