ruby – 如何将布尔值转换为整数?

前端之家收集整理的这篇文章主要介绍了ruby – 如何将布尔值转换为整数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个布尔值来检查它是否为true,然后设置一个局部变量.如何重构这个,这样它就是 Ruby-ish呢?
if firm.inflection_point
  inflection_point = 1
else
  inflection_point = 0
end

解决方法

inflection_point = (firm.inflection_point ? 1 : 0)
原文链接:https://www.f2er.com/ruby/273138.html

猜你在找的Ruby相关文章