Hello everyone,

I just ran into a problem with Strings that really confuses me.

This code, using Arrays, works as I would expect.

a = [1,2,3]
b = a.dup
a.reverse!
a             # -> [3, 2, 1]
b             # -> [1, 2, 3]

Nothing strange there. But some similar code, using String:

a = "hello"
b = a.dup
a.reverse!
a             # -> "olleh"
b             # -> "olleh"

I would have expected 'b' to be unaffected, since it's supposed to be a
different object than 'a'. So I figured that this had to be something with
how String#dup worked, so I tried String#clone insted. This had the exact
same result.
I guess there is some totally logical reason for this String behaviour,
but I first thought that I was hallucinating when I saw it. :-)
I hope that someone can enlighten me about this.

/Anders
_____________________________________________________________________
A n d e r s  B e n g t s s o n                   ndrsbngtssn / yahoo.se
Stockholm, Sweden


_____________________________________________________
Do You Yahoo!?
S?lj eller l?gg ett bud p? Yahoo! Auktioner http://se.auctions.yahoo.com