Skip to content
instance method

Array#compact!

() -> self?
compact! → self or nil

Removes all nil elements from self; Returns self if any elements are removed, nil otherwise:

Example
a = [nil, 0, nil, false, nil, '', nil, [], nil, {}]
a.compact! # => [0, false, "", [], {}]
a          # => [0, false, "", [], {}]
a.compact! # => nil

Related: Array#compact; see also Methods for Deleting.

See also #compact #concat #combination #count also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0