ruby-on-rails - ruby 条件判断怎么实现最好
阿神
阿神 2017-04-25 09:01:33
0
1
837

需要判断来输出string,用的如下

string1 || string2

但是条件变复杂了

如果 string1 有,就输出 string1, 不然如果 boolean1 是 true, 则输出 string2, 不然输出 string3

这样写似乎不对
string1 || boolean1 ? string2 : string3

请问有什么比较好的写法吗? 还是用 if else 来判断?

update:
加个括号就可以了..
string1 || (boolean1 ? string2 : string3)

阿神
阿神

闭关修行中......

répondre à tous(1)
phpcn_u1582

Cette façon d'écrire peut également être utilisée

  data =
         if  boolean
             string1
         elsif boolean1
             string2
         else 
             string3
             
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!