Ruby exclude from slice

# Given array
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

# Excluding elements using slice
new_arr = arr.slice(2..-2)

puts new_arr

Explanation:

  1. Given Array: The initial array arr is created with the values [1, 2, 3, 4, 5, 6, 7, 8, 9].
  2. Excluding Elements: The slice method is used to create a new array new_arr by excluding elements from index 2 to the second-to-last index of the original array arr.
  3. Print Result: The puts method is used to print the content of the new_arr array, which will exclude elements from index 2 to the second-to-last index of the original array.