public Method

Array.compact

array.compact       an_array

Returns a copy of self with all nil elements removed.

[ "a", nil, "b", nil, "c", nil ].compact

> [ "a", "b", "c" ]

Source Code

/*
*  call-seq:
*     array.compact     ->  an_array
*
*  Returns a copy of _self_ with all +nil+ elements removed.
*
*     [ "a", nil, "b", nil, "c", nil ].compact
*                       #=> [ "a", "b", "c" ]
*/

static VALUE
rb_ary_compact(ary)
   VALUE ary;
{
   ary = rb_ary_dup(ary);
   rb_ary_compact_bang(ary);
   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.