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文をシンプルに書けます。
普通のif文

if 条件
 式1
else
 式2
end

三項演算子

条件 ? 式1 : 式2

となります
【例】if文

def add_button_name
    if controller.action_name == 'show'
      "コメントを投稿する"
    else
      "コメントを更新する"
    end
  end

【例】三項演算子

def add_button_name
  controller.action_name == 'show' ? "コメントを投稿する" : "コメントを更新する"
end

になります。

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?