Truncate an array

Is there a generally preferred way to truncate an array? I’ve used
these two, but is there a better way?

SOME_ARRAY = [1, 2, 3]

  1. SOME_ARRAY.each_index{|i| SOME_ARRAY[i].nil}.compact!
  2. SOME_ARRAY.slice!(1…0)

=> SOME_ARRAY == []

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs