From: dblack@... Date: 2002-11-26T12:56:34+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (11/24/02) Hi -- On Tue, 26 Nov 2002, Daniel Carrera wrote: > [snip] > > 4 is an unmodifiable object. "Hello".chomp! is fine because "Hello" is a > > modifiable object. > > Thanks, I'm understanding more now. I guess that the next logical > question is why is 4 unmodifiable and "a" modifiable? I don't see why a > string would be modifiable and a number not. > > Just like you can say that the number 4 is set, and cannot be turned into > a 5, you can also say that the letter "a" is set and cannot be turned into > a "b". Yet, I can write: > > "a".gsub!(/a/,"b") You're not changing the letter 'a' itself; you're changing a string which has the letter 'a' in it. To put it another way: You can have more than one "a" string: s = "a" t = "a" and if you change or increment s: s.succ! # s is now "b" t doesn't change. But there's only one of each number. If you were allowed to do 3.succ! or 3 += 1 then when you did this: puts 3 * 5 the output would be "20", because you would have incremented the actual object 3. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav