public Method

Array.clear

array.clear      array

Removes all elements from self.

a = [ "a", "b", "c", "d", "e" ]
a.clear    #=> [ ]

Source Code

/* 
*  call-seq:
*     array.clear    ->  array
*
*  Removes all elements from _self_.
*
*     a = [ "a", "b", "c", "d", "e" ]
*     a.clear    #=> [ ]
*/

VALUE
rb_ary_clear(ary)
   VALUE ary;
{
   rb_ary_modify(ary);
   RARRAY(ary)->len = 0;
   if (ARY_DEFAULT_SIZE * 2 < RARRAY(ary)->aux.capa) {
       REALLOC_N(RARRAY(ary)->ptr, VALUE, ARY_DEFAULT_SIZE * 2);
       RARRAY(ary)->aux.capa = ARY_DEFAULT_SIZE * 2;
   }
   return ary;
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.