我怎么布尔值转换为整数? [英] How do I convert boolean values to integers?

查看:1029
本文介绍了我怎么布尔值转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布尔值,以检查它是否是真的,然后设置一个局部变量。我如何重构这个所以它更红宝石十岁上下的?

 如果firm.inflection_point
  inflection_point = 1
其他
  inflection_point = 0
结束


解决方案

  inflection_point =(firm.inflection_point 1:0)

I have a boolean value to check if it is true, then set a local variable. How do I refactor this so it is more Ruby-ish?

if firm.inflection_point
  inflection_point = 1
else
  inflection_point = 0
end

解决方案

inflection_point = (firm.inflection_point ? 1 : 0)

这篇关于我怎么布尔值转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆