5
5

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

Ruby | nil? もしくは empty? を同時に判定する

5
Last updated at Posted at 2016-07-14

こんな感じ。

variable.to_s.empty?

文字列の場合

''.to_s.empty? # => true

nil.to_s.empty? # => true

配列の場合

nil.to_a.empty? # => true

[].to_a.empty? # => true

ハッシュの場合

nil.to_h.empty? # => true

{}.to_h.empty? # => true

環境

  • ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?