Is there a standard way to convert a Ruby string to either an integer or float depending on the string?

72 Views Asked by At

Is there a function in the standard Ruby library or in ActiveSupport which works like this?

f("1.5") == 1.5
f("1") == 1 # Not 1.0
f("1.0") == 1.0

Of course I can easily write my own, but wanted to ask in case I overlooked a built-in solution.

0

There are 0 best solutions below