From: Caleb Clausen Date: 2009-12-22T12:45:10+09:00 Subject: Re: Strange behavior of unary +@ for Fixnum? On 12/21/09, Colin Bartlett wrote: > I haven't looked at the source code, but I think I'm right in saying that > Ruby parses (-7) as an _integer literal_, unless it's an expression like > (-7**2) > in which case it's parsed as (-(7**2)), that is (7**2).send( :-@ ) > By analogy, it seems that the parser is treating (+7) as an integer literal, > not as 7.send( :+@ ) ? This is correct. + or - at the start of an numeric literal is tokenized as part of that literal. (Except in the ** case, as you say.) The situation is somewhat better in 1.9, where at least + 7 #with a space in between is treated as +@ method applied to the literal 7. But that doesn't help in 1.8. Note that in ruby 1.8, any number of leading + signs are glommed into the integer literal: ++++++++++++++++++++++++++7 #still no method call in 1.8 Having integer literals eat up the leading + or - as part of the number token is a common 'optimization' in many languages...