This is a read-only archive!

Why no pre/post increment/decrement in Ruby?

I've been wondering why you can't do c++ in Ruby. Finally I found this post by Matz explaining (in somewhat broken English).

I guess it make sense, given that in Ruby, variables are essentially just names or aliases for objects. So c = 1; c++ would be the same as 1++. What would 1++ mean in any language? "Add 1 to 1, and assign the resulting value to 1"? Best you could do is have c++ return a new separate 2 object, which isn't what you'd expect if you come from a C-like background.

August 07, 2007 @ 1:36 PM PDT
Cateogory: Programming
Tags: Ruby