From: "Aleksi Niemelä" Date: 2000-05-10T17:26:20+02:00 Subject: [ruby-talk:02711] Re: X++? In message "[ruby-talk:02706] X++?" on 00/05/10, Aleksi Niemel� writes: >|I got an idea from http://www.pragprog.com:8080/rubyfaq/rubyfaq-5.html#ss5.3 >|and thought to try. I didn't manage to make "auto(in|de)crement" working so > (1) ++ and -- are NOT reserved operator in Ruby. Yes, I know. I just wanted to have a = integer; a.++ where we call a's method ++ which increment's a's value by one. > (2) C's increment/decrement operators are in fact hidden assignment. > They affect variables, not objects. You cannot accomplish > assignment via method. Ruby uses +=/-= operator instead. This was good to know. Actually I'm not sure what I've been thinking, but maybe I took it granted that one could write method for assignment. Maybe this was coming to me from C++. Brrr. I got some bad vibrations... > (3) self cannot be a target of assignment. In addition, altering > the value of integer 1 might cause severe confusion throughout > the program. Oh, now I see. Object Fixnum *is_a* number. It does not *have_a* number like Integer class in Java. So 5.++ could return 6. But without implicit assigment X.++ does not make any sense. Well, I'm not going to create Integer just for fun of def ++ self.i += 1 end Happy enough? :-) I have to add that I was just trying to bend the language instead of bringing yet another Bad Idea (tm) into it. - Aleksi