Ruby 3.4 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Enumerableモジュール > compact
compact -> Array
[permalink][rdoc]self から nil を取り除いた配列を生成して返します。
def with_nils
yield 1
yield 2
yield nil
yield 3
end
to_enum(:with_nils).compact # => [1, 2, 3]
[SEE_ALSO] Array#compact