From: "Berger, Daniel" Date: 2006-07-26T23:36:06+09:00 Subject: Re: Truncate an array > -----Original Message----- > From: Aleks Kissinger [mailto:aleks0@gmail.com] > Sent: Wednesday, July 26, 2006 8:31 AM > To: ruby-talk ML > Subject: 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 == [] SOME_ARRAY = [] Regards, Dan This communication is the property of Qwest and may contain confidential or privileged information. Unauthorized use of this communication is strictly prohibited and may be unlawful. If you have received this communication in error, please immediately notify the sender by reply e-mail and destroy all copies of the communication and any attachments.