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?

Rails 判定メソッド早見表

0
Last updated at Posted at 2026-03-17
値 .nil? .empty? .blank? .present?
nil true エラー true false
""(空文字) false true true false
" "(空白1文字) false false true false
"abc" false false false true
[](空配列) false true true false
[1,2] false false false true
{}(空ハッシュ) false true true false
0(整数) false エラー false true
false false エラー true false

ポイント整理

•	.nil? → そのオブジェクトが nil かどうか(nil だけ true)
•	.empty? → 長さ0かどうか(String / Array / Hash にしかない)
•	.blank? → Rails 拡張。「nil or 空 or 空白文字だけ」なら true
•	数値 (0) は「blank ではない」
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?