From: Seebs Date: 2010-02-09T04:20:06+09:00 Subject: Re: Why no ++ and --? On 2010-02-08, Sonja Elen Kisa wrote: > "foo += 1" somehow seems less elegant or pretty as "foo++". > Is there any reason Ruby doesn't have ++? Yes. > Is it something that might be > added in a future version? Very unlikely. In Ruby, "foo" is not an object, it's a reference to an object. Not all objects are mutable. After: foo = 3 "foo" is just a name to refer to the Fixnum 3. That object CANNOT be modified. When you write: foo = foo + 1 what happens is: We extract the current value of foo (fixnum 3). We send that an add message with the other argument being the fixnum 1 That yields a new object, the fixnum 4 Foo is changed to be a reference to that new object You can't increment the underlying object, because fixnums are immutable. -s -- Copyright 2010, 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!