Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
39
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@18sasaki

Ruby on Railsのtrue/false まとめ

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。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
39
Help us understand the problem. What are the problem?