From: Matthew Kerwin Date: 2013-04-15T12:23:49+09:00 Subject: Re: Wondering why no "increment" or "decrement" operator in ruby tamouse mailing lists wrote in post #1105638: > Seems like every other language I've encountered since learning C way > back in the Jurassic, has had an increment (++) or decrement (--) > operator, and I've been wondering why Ruby doesn't. I haven't gone off > looking for the answer, but I think I have figured out why it can't > work, roughly, in general, and > not-really-knowing-the-deep-implementation reasons why. > > Basically, because you cannot do something like this: > > 1.increment > > and expect your 1 to start having the value of 2. Since 1 is an object > that is an instance of Fixnum, and doing > > a = 1 > > basically is just saying `a` points the object `1`, you can't have > `a.increment`, either. > > Have I got it? In a word: yes. You don't have the ability to perform an action on the variable 'a' except by assignment; all you can do is send messages to the object it references. And there is always only exactly one 1, and it is never equal to 2. Incidentally, if you're using MRI, because of a clever optimisation your 'a' variable literally holds the value `1`, not a reference per se. -- Posted via http://www.ruby-forum.com/.