"Caio Tiago Oliveira" <caiot1 / ibest.com.br> schrieb im Newsbeitrag
news:42025196.2050502 / ibest.com.br...
> BearItAll, 3/2/2005 09:05:
>
> > Strange really how I read that "Returns a new string..." a billion
> > times, without actually noticing what it said.
>
> @x = @x.chop
> is the same as
> @x.chop!

No, it is not.  In many applications this might be equivalent but it's not
the same.  @x.chop! does not create a new instance, i.e. whoever holds a
reference to that instance sees the change.  @x=@x.chop creates a new
instance so everybody else referencing the old value of @x sees no change.
Also, it makes a difference when you consider #freeze:

>> s = "abcd"
=> "abcd"
>> s.freeze
=> "abcd"
>> s.chop!
TypeError: can't modify frozen string
        from (irb):3:in `chop!'
        from (irb):3
>> s = s.chop
=> "abc"

Also, it makes a difference performance wise.  The first form is usually
slower since a new instance has to be created.

> @x.chop return a new string you can assing to a variable you want to.

Yes.

Kind regards

    robert