On 2009-11-04, RichardOnRails <RichardDummyMailbox58407 / 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? If not, you haven't implemented an increment operator. > Appending these lines shows that a & b values are distinct. > That is, after incrementing, a =2, b is unchanged; b is not > impacted by a?s change > a += 1; show (a) => Got 2; class = Fixnum; object_id = 5; v >> 1 >= 2 > show (b) => Got 1; class = Fixnum; object_id = 3; v >> 1 = 1 Right. You've changed which object a refers to, because you've reassigned a. > Appending these lines shows the ++?s alias pp works just find > a=1; show(a.pp) => Got 2; class = Fixnum; object_id = 5; v >> 1 >= 2 > show(b) => Got 1; class = Fixnum; object_id = 3; v >> 1 = 1 Not the same. The key is that, after "a += 1", not only do you get 2, 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. Peter Seebach / usenet-nospam / seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!