From: Lothar Scholz Date: 2005-06-05T06:04:02+09:00 Subject: Re: Question about string's in-place modification Hello Sam, SK> Hello! SK> I wonder how destructive methods work in the behind. SK> For example, SK> s = '12345' SK> s2 = s SK> s.sub!('3', 'three') puts s #->>'12three45' puts s2 #->>'12three45' SK> Destructive methods are in-place. SK> Does that mean the object doesn't change its location in memory? SK> Probably not. SK> I don't think it's possible as the object might need more space and SK> need to move to a bigger empty space for the changed data. SK> If it moves, the references pointing to it should be updated as well. SK> How exactly does that work? A string is of c type VALUE (as every ruby object). This c type hold at least 16 byte. So there is enough space to keep a string length and the pointer inside the object. SK> Thanks in advance. SK> Sam -- Best regards, emailto: scholz at scriptolutions dot com Lothar Scholz http://www.ruby-ide.com CTO Scriptolutions Ruby, PHP, Python IDE 's