How do I convert boolean values to integers?

后端 未结 7 1081
日久生厌
日久生厌 2020-12-16 10:39

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
  inflectio         


        
7条回答
  •  醉酒成梦
    2020-12-16 10:59

    Another alternative is use of short-circuit operators:

    inflection_point && 1 || 0
    
    
    irb(main):001:0> true && 1 || 0
    => 1
    irb(main):002:0> false && 1 || 0
    => 0
    

提交回复
热议问题