Method: Array#compact
- Defined in:
- array.c
#compact ⇒ Object
Returns a new array containing only the non-nil elements from self; element order is preserved:
a = [nil, 0, nil, false, nil, '', nil, [], nil, {}]
a.compact # => [0, false, "", [], {}]
Related: Array#compact!; see also Methods for Deleting.
6433 6434 6435 6436 6437 6438 6439 |
# File 'array.c', line 6433 static VALUE rb_ary_compact(VALUE ary) { ary = rb_ary_dup(ary); rb_ary_compact_bang(ary); return ary; } |