主页

ruby三元表达式

2023-09-08 11:15AM

Ruby 中的三元表达式是一种条件语句,其语法为:

条件 ? 结果1 : 结果2

如果条件为真,则返回结果1,否则返回结果2。

eg:

 <% text =  enterprise.monitor_status ? '关闭监控' : '开启监控' %>

如果 monitor_status 为 true,则将 text 为 '关闭监控';如果 monitor_status 为 false,则将 text 为 '开启监控'。

 

 

返回>>

登录

请登录后再发表评论。

评论列表:

目前还没有人发表评论