[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Truncate an array

Aleks Kissinger

7/26/2006 2:31:00 PM

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 == []