Truncate an array

Discussion in 'Ruby' started by Aleks Kissinger, Jul 26, 2006.

  1. 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.nil}.compact!
    2. SOME_ARRAY.slice!(1..0)

    => SOME_ARRAY == []
    Aleks Kissinger, Jul 26, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yannick Turgeon

    Regexp to truncate

    Yannick Turgeon, Oct 11, 2003, in forum: Perl
    Replies:
    1
    Views:
    436
    Yannick Turgeon
    Oct 13, 2003
  2. Eddie
    Replies:
    1
    Views:
    9,681
    Arthur Yousif
    Dec 23, 2003
  3. Replies:
    4
    Views:
    511
    Jack Klein
    Jun 5, 2004
  4. Natevw

    truncate end of file

    Natevw, Nov 3, 2004, in forum: C++
    Replies:
    1
    Views:
    3,176
    Victor Bazarov
    Nov 3, 2004
  5. A. Farber
    Replies:
    3
    Views:
    193
    A. Farber
    Aug 28, 2008
Loading...

Share This Page