ruby array minus array

To subtract one array from another in Ruby, you can use the "-" operator. This will remove any elements from the first array that are also present in the second array. Here is an example:

array1 = [1, 2, 3, 4, 5]
array2 = [3, 4, 5, 6, 7]

result = array1 - array2

Explanation of each step:

  1. We declare an array called array1 and assign it the values [1, 2, 3, 4, 5].
  2. We declare another array called array2 and assign it the values [3, 4, 5, 6, 7].
  3. We use the "-" operator to subtract array2 from array1, resulting in a new array called result.
  4. The elements [3, 4, 5] are present in both array1 and array2, so they are removed from array1 in the result.
  5. The final value of result is [1, 2].

This is how you can subtract one array from another in Ruby using the "-" operator.