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]
- SOME_ARRAY.each_index{|i| SOME_ARRAY[i].nil}.compact!
- SOME_ARRAY.slice!(1…0)
=> SOME_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]
=> SOME_ARRAY == []
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs