From: "Hal E. Fulton" Date: 2003-03-27T08:02:20+09:00 Subject: Re: syntax ----- Original Message ----- From: To: "ruby-talk ML" Sent: Wednesday, March 26, 2003 4:15 PM Subject: Re: syntax > irb(main):006:0> class Fixnum > irb(main):007:1> def inc(val=1) > irb(main):008:2> self += val > irb(main):009:2> end > irb(main):010:1> end > SyntaxError: compile error > (irb):8: Can't change the value of self > self += val > ^ > from (irb):10 > irb(main):011:0> ^C > (%:~)- ruby -v > ruby 1.6.7 (2002-03-19) [i386-linux] > > > > > Robert wrote: > > >class Fixnum > > def inc(val=1) > > self += val > > end > >end > > > >1.inc > > > >:-) > > Rodrigo, I think Robert was being facetious. This can't work for a variety of reasons. Robert's point (I think) was: What do you get if you increment a constant? It's surely wrong to change all values of 1 to something else. For example, if you actually *could* transform the object 1 into the object 2, then this code fragment x = 1 y = 1.inc puts x would print 2 rather than 1. The lack of a ++ operator (and the rationale behind it) has been discussed many times over the last three years or so. If it's not in the FAQ at http://www.rubygarden.org/iowa/faqtotum -- well, it should be. :) And you can also search the list archives at www.ruby-talk.org (search for ++ or increment). Cheers, Hal