From: Matt Greer Date: 2007-07-21T04:22:25+09:00 Subject: Re: Is there a replacement for sub? ------=_Part_138552_28783653.1184959348627 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/20/07, Michael W. Ryder <_mwryder@worldnet.att.net> wrote: > > > > a = "a b c d e f" > > b = a > > a = a.sub(" ", "") # => a is now "ab c d e f", b is still "a b c d e f" > > > Wrong. Unless you use b = a.dup b will be the same as a as it is > pointing to the same object. The result of the sub operation will > change b as well as a. The original author was correct. b points to "a b c d e" a gets replaced with "ab c d e" and b still points to the original string. You're thinking something like a = [1,3,4] b = a a[0] = 5 a and b are both [5,3,4] irb(main):001:0> a = "a b c d e" => "a b c d e" irb(main):002:0> b = a => "a b c d e" irb(main):003:0> a = a.sub(" ", "") => "ab c d e" irb(main):004:0> a => "ab c d e" irb(main):005:0> b => "a b c d e" irb(main):006:0> Matt ------=_Part_138552_28783653.1184959348627--