From: Hal Fulton Date: 2004-04-24T03:35:20+09:00 Subject: Re: Creating bang methods Jean-Hugues ROBERT wrote: >> This is also why there are no ++ and -- operators in Ruby. 1++ would >> mean that the actual number 1 would henceforth mean 2. >> David > > > Well... something++ could get expanded into (something = something.++()) ? > And ++something get expanded into (tmp = something, something = > something.++(), tmp) > Pure syntax sugar. > Then you can: > def ++() > self + 1 > end > I think += does that already, doesn't it ? > There are other reasons why there is no ++ in Ruby. Well, my impression is that Matz doesn't like for assignment to be done except where it's painfully obvious there's an assignment. Assignment is not considered a true operator in Ruby. (Yes, it has precedence, but it operates on variables, not on objects.) But we are used to thinking of ++ and -- as operators, not as assignment. This may be part of the reason. But IANYM. Also IMO these operators can encourage some obfuscated code which would be better written another way. Of course, both parts of my statement are debatable. Hal