How does ruby do the + operator?
问题 Ruby does not support incrementing variables like variable++ . I saw this behaviour that: 2 ++ 4 gives 6 . In fact, any number of + signs between two variables are treated as one single + . How does ruby manage that? And since ruby does that, can it be taken as the reason for the unavailability of the ++ operator? 回答1: This: 2 ++ 4 is parsed as: 2 + (+4) so the second + is a unary plus. Adding more pluses just adds more unary + operators so: 2 ++++++ 4 is seen as: 2 + (+(+(+(+(+(+4)))))) If