From: Austin Ziegler Date: 2005-03-04T00:13:35+09:00 Subject: Re: post inc problem On Thu, 3 Mar 2005 23:34:35 +0900, Brian Schr�der wrote: > > > Is the "++" syntax used for some other operation, thus precluding > > > its use for a synonym for increment. And wouldn't the right thing > > > for ++ be to increment to the next number? > > > > This comes up every so often, and as much as it has to do with the > > problem of mutating a fixed value (e.g., 5++), it has much more to > > do with the understanding of Ruby variables and the true nature of > > object orientation in Ruby, as well as operator overriding. > > > > At least, IMO. > > > > There's two ways to implement ++. The first way is to implement it > > as an operator, like #+ and #*. Because it is a unary operator, it > > would probably be something like: > > > > def @++ > > # implementation > > end > > > > OK. That's fine. > > Maybe I didn't understand you, but how would such an implementation > look like? The problem as I see it, is that we are sending messages to > the object and not to the variable. So we can't increment the > variable, because we don't know it. Well, that's part of what I forgot to mention; had a scrum meeting coming up and forgot to finish the email. Since Ruby's variables don't actually occupy "space" (as objects do), then #@++ wouldn't do any good in any case, which leaves you with the syntax sugar. Maybe a combination, if we really wanted this: a++ # actually: a = a.@++ ++a # actually: a = a.@++@ Or something. But that makes it even less acceptable, as the amount of magic required to do that is very high. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca