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
If you just have that at one point, then rudolph9's answer is good, but if you are having a similar kind of logic all over the place, then maybe it might make sense with general use in mind to monkey patch:
class FalseClass; def to_i; 0 end end
class TrueClass; def to_i; 1 end end
inflection_point = firm.inflection_point.to_i
Within Ruby, you should keep all of your logic dealing with truth values rather than 0
and 1
, but I guess you are dealing with some inputs or outputs from/to some external system that deals with 0
and 1
. Then, doing like this will make sense.