0
0

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 5 years have passed since last update.

presence メソッド

Posted at

presenceメソッドは

def presence
  self if present?
end

で定義されている

使い所

例えば、site_titleというWebページのタイトルを返すメソッドの場合、このような実装になるかと思います。

def site_title(title)
  title.present? ? title : 'サイト名'
end

これをpresenceを使うと下記のようになります。

def site_title(title)
  title.presence || 'サイト名'
end

REFERENCE

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?