From: Morgan Grubb Date: 2007-08-21T01:34:05+09:00 Subject: Re: Assignment as a reference? ------=_Part_125046_28474116.1187627649687 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks for that. I've been reading through quite a few references and manuals (working through Agile Web Development at the moment) and the fact that every assignment is a reference hasn't really been mentioned that much. Guess I've missed it or haven't gotten that far. Cheers. On 20/08/07, Douglas F Shearer wrote: > > > On 20 Aug 2007, at 17:20, Morgan Grubb wrote: > > foo = 'bar' #=> bar > > foo2 = foo #=> bar > > foo.gsub! 'bar', 'wibble' #=> wibble > > foo2 #=> wibble > > What you have experienced is reference assignment. If you wish to > duplicate only the content, and not the reference, then you should to > use .dup. > > > foo = "bar" > => "bar" > > foo2 = foo.dup > => "bar" > > foo = "wibble" > => "wibble" > > foo2 > => "bar" > > Hope this helps you out. > > Douglas F Shearer > dougal.s@gmail.com > http://douglasfshearer.com > > ------=_Part_125046_28474116.1187627649687--