Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Truncate an array

Thread Tools

Truncate an array

Aleks Kissinger
Posts: n/a
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 == []

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Truncate an array when you have a ref to it? A. Farber Perl Misc 3 08-28-2008 06:11 AM
truncate end of file Natevw C++ 1 11-03-2004 06:27 PM
how to truncate a file C++ 4 06-05-2004 04:43 AM
truncate time from date in DataTable.Select() Eddie ASP .Net 1 12-23-2003 10:55 PM
Regexp to truncate Yannick Turgeon Perl 1 10-13-2003 02:09 AM