compact -> Array[permalink][rdoc][edit]-
自身から nil を取り除いた配列を生成して返します。
例ary = [1, nil, 2, nil, 3, nil] p ary.compact # => [1, 2, 3] p ary # => [1, nil, 2, nil, 3, nil][SEE_ALSO] Array#compact!
このマニュアルは既にメンテナンスが終了したバージョンの Ruby を対象としています。 最新版のマニュアルへ
compact -> Array[permalink][rdoc][edit]自身から nil を取り除いた配列を生成して返します。
例ary = [1, nil, 2, nil, 3, nil]
p ary.compact # => [1, 2, 3]
p ary # => [1, nil, 2, nil, 3, nil]
[SEE_ALSO] Array#compact!