43
39

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.

Ruby on Railsのtrue/false まとめ

Posted at
xxx.nil? xxx.empty? xxx.blank? xxx.present? if xxx
nil True Error True False False
0 False Error False True True
1 False Error False True True
"" False True True False True
" " False False True False True
"word" False False False True True
[] False True True False True
[nil] False False False True True
[0] False False False True True
[""] False False False True True
[" "] False False False True True
["word"] False False False True True
{} False True True False True
{:ni => nil} False False False True True
{:ze => 0} False False False True True
{:bl => ""} False False False True True
{:sp => " "} False False False True True
{:wo => "word" False False False True True
nilかどうかだけ 入れ物の中身が入っているか入っていないか。スペースは""の中にスペースが入っているのでfalse。[nil][""]も、nilや空の文字列が入っているのでfalse。 nilかどうか(nil?)+空かどうか(empty?)+スペースだけかどうか 単純にblank?の反対。スペースはあるとはみなされない。 単純にnil?の反対。なにかしらの入力があればTRUE。
43
39
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
43
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?