compact! -> self | nil[permalink][rdoc][edit]-
自身から破壊的に nil を取り除き、変更が行われた場合は self を、そうでなければ nil を返します。
例ary = [1, nil, 2, nil, 3, nil] ary.compact! p ary # => [1, 2, 3] p ary.compact! # => nil[SEE_ALSO] Array#compact
このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ
compact! -> self | nil[permalink][rdoc][edit]自身から破壊的に nil を取り除き、変更が行われた場合は self を、そうでなければ nil を返します。
例ary = [1, nil, 2, nil, 3, nil]
ary.compact!
p ary # => [1, 2, 3]
p ary.compact! # => nil
[SEE_ALSO] Array#compact