如何将布尔值转换为整数? [英] How do I convert boolean values to integers?
本文介绍了如何将布尔值转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个布尔值来检查它是否为真,然后设置一个局部变量.我该如何重构它以使其更像 Ruby?
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屋!
查看全文