Ruby - Array Subtraction and Difference

Introduction

You can compare two arrays by subtracting one against the other.

This technique removes any elements from the main array that are in both arrays:

Demo

x = [1, 2, 3, 4, 5] 
y = [1, 2, 3] #   www  .j a  va2s.  c  o m
z = x - y 
p z

Result