10
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

rails6.1から追加された`compact_blank`について

Last updated at Posted at 2021-12-28

概要

例えば、Arrayにnilが入りうる可能性がある場合にnilを取り除きたいケースがあった場合に最小の行動で表すとreject(&:blank?)を使っていたがその処理のショートハンドができました。

> [1, 2, nil, 3, "", []].compact_blank
=> [1, 2, 3]

> [1, 2, nil, 3, "", []].compact_blank
=> [1, 2, 3]

追加されたPR

10
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?