How do I use the conditional operator (? :) in Ruby?

前端 未结 7 2365
無奈伤痛
無奈伤痛 2020-11-22 10:34

How is the conditional operator (? :) used in Ruby?

For example, is this correct?

<% question = question.size > 20 ? question.ques         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 10:57

    Easiest way:

    param_a = 1
    param_b = 2
    
    result = param_a === param_b ? 'Same!' : 'Not same!'
    

    since param_a is not equal to param_b then the result's value will be Not same!

提交回复
热议问题