On Nov 4, 2:13 ¨Βν¬ ΣεεβΌυσεξετξοσ®®®ΐσεεβσ®ξετχςοτεΊ > On 2009-11-04, RichardOnRails <RichardDummyMailbox58... / USComputerGurus.com> wrote: > > > class Fixnum > > def pp # We can?t define ++ because of a compiler restriction. > > self + 1 > > end > > end > > This doesn't seem to do the right thing. > > a = 1 > a.pp > > Is a now 2? ¨Βξοτ¬ ωοθαφεξ§ινπμενεξτεαξ ιξγςενεξοπεςατος> > > Appending these ¨Βιξεσ σθοχτθατ φαμυεσ αςδιστιξγτ> > That is, ¨Βζτες ιξγςενεξτιξη ¨Β ½² ¨Β ισ υξγθαξηεδ» ισ ξο> > impacted by a?s change > > a += 1; show (a) > ¨Βοτ ²» ¨Βμασσ Ζιψξυνοβκεγτίιδ³µ» ¨Β ΎΎ > >= 2 > > show (b) > ¨Βοτ ±» ¨Βμασσ Ζιψξυνοβκεγτίι³» ¨Β ΎΎ > > Right. ¨Βου§φγθαξηεχθιγοβκεγτ ςεζεςσ τοβεγαυσωου§φε ςεασσιηξεδ > a. > > > Appending these ¨Βιξεσ σθοχτθ««Ώσ αμιαππ χοςλκυστ ζιξδ > > a=1; show(a.pp) > ¨Βοτ ²» ¨Βμασσ Ζιψξυνοβκεγτίιµ» ¨Β ΎΎ > >= 2 > > show(b) > ¨Βοτ ±» ¨Βμασσ Ζιψξυνοβκεγτίι³» ¨Β ΎΎ > > Not the same. ¨Βθε λεισ τθαταζτεΆα «½ ±Άξοοξμω δο ωοη岬 > but a is now 2. > > > Do you agree? > > No. > > For "a.pp" to be the same as a++ in other languages, you'd have to do: > > a = 1; a.pp; show(a) => Got 2 > > If you don't get a "2" by using a.pp, it's not an increment, just a "one > more than". > > Consider a loop: > > a = 1 > while ((a += 1) < 10) do > puts a > end > > Now, try: > > a = 1 > while (a.pp < 10) do > puts a > end > > Doesn't do the same thing. > > -s > -- > Copyright 2009, all wrongs reversed. ¨Βετες Σεεβαγυσεξετξοσ®®®ΐσεεβσ®ξετθττπΊ――χχχ®σεεβσ®ξετ―μοη―ΌμαχσυιτσςεμιηιοξαξζυξξπιγτυςεσθττπΊ――εξ®χιλιπεδια®οςη―χιλι―ΖαιςίΗανεί¨Σγιεξτομοηω© Όηεεδυγατεδ Hi Peter, > This doesn't seem to do the right thing. > > a = 1 > a.pp > > Is a now 2? If not, you haven't implemented an increment operator. Thanks for this question. You're so right. I couldn't see it until you pointed it out. class Fixnum def pp # We canΓΥ define ++ because of a compiler restriction. self + 1 end end doesn't change self (which Ruby won't allow for Fixnum's!!! Which, of course, is why your: a = 1 while (a.pp < 10) do puts a end produces an infinite number of 1's ..., or would if RAM were infinite and hardware addressing mechanisms were infinite. I grateful for you taking the time to identify my deficiencies. Best wishes, Richard