What you see printed as Infinity and NaN are just string representations for two special instances of the Float class, not keywords or literals. They are returned by dividing by floating point by 0 or by referencing the constants Float::INFINITY and Float::NAN .
Float::INFINITY.class # => Float Float::INFINITY.to_s # => "Infinity" Float::NAN.class # => Float Float::NAN.to_s # => "NaN"
source share