ruby: use ruby's built-in support to test for infinity and nan

Ruby's Float class already has constants to define NaN and Infinity as well as built-in support to test whether a float is a nan or an infinity. Use them instead of our own custom-made code.