[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Assignment as a reference?

dougal.s

8/20/2007 4:28:00 PM


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://douglasfs...