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?

More than 3 years have passed since last update.

三項演算子

Posted at

三項演算子とは

if文を1行で記述することができるため、すっきりとしたコードを記述できる
しかし、複雑なif文には使用すると逆に読みにくいコードになってしまうため
シンプルなif文にのみ使用する

var = "文字列"

if var.class == String
  "varはStringです"
else
  "varはStringではありません"
end

このif文を三項演算子に変換すると

条件 ? 1(true) : 2(false)
var = "文字列"
var.class == String ? "varはstringです" : "varはstringではありません"
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?