damonh damonh - 5 months ago 12
Ruby Question

How is a negative number parsed in Ruby?

Say

-1
, is
-
parsed as part of the literal as a sign, or an operator to turn the value into its negative counterpart?

Answer

It is parsed as part of the literal, and makes the literal a negate literal.

Here's the reference in the parser source code. If you search the file for tUMINUS_NUM and tUMINUS you'll see where the - token is defined.