30
31

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.

eachのelseの書き方

Last updated at Posted at 2012-11-07

2012/11/7 追記:個人的には面白いとは思いますが、クリーンな書き方だと思ってないので参考程度にお願いします。

例えばブログのシステムなどで投稿がないときに”投稿はありません”って表示するような場合。
なんか他にいい方法があった気がするので、下記よりまともな方法をだれか教えてください。

if @posts.each do |post|
  # do something
end.empty?
  # ポストはありません
end
30
31
3

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
30
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?