From: "Daniel Carrera" <dcarrera / math.umd.edu>


> > It's applicable to a small subset of the total set of classes.
> > Really, x++ is the same as x.succ!, and x.succ! won't work because
> > there's no assignment and you can't change self.
>
> I don't follow that.  Why is it that I can do string.chomp! but it is not
> conceivable to do x.succ!?  Aren't you changing self with string.chomp!?
>
> Daniel.


No.  Hopefully the following makes sense.

irb(main):001:0> s = "String\n"
"String\n"
irb(main):002:0> s.id
134560740
irb(main):003:0> s.chomp!
"String"
irb(main):004:0> s.id
134560740
irb(main):005:0> x = 4
4
irb(main):006:0> x.id
9
irb(main):007:0> x += 1
5
irb(main):008:0> x.id
11

The prevailing point is that "x = 4; x++" translates into Ruby most closely as
  x = 4
  x.succ!

Of course, Integer#succ! is not defined, for good reason.  What does
  4.succ!
mean?  Turn all 4's into 5's?

4 is an unmodifiable object.  "Hello".chomp! is fine because "Hello" is a
modifiable object.

Gavin