I stumbled upon this line of Ruby in our codebase:
value = value.to_i if value == value.to_i
and I can’t understand what it is supposed to do.
If the guard condition is false, it does nothing.
If it is true, it’s a noop.
What gives?
>Solution :
This line of code will cast any integer number to the Integer class, so it will replace 2.0 or BigDecimal(2) with 2. This might be useful if you have code later on which cares about the class of value.