[sc-users] Temporary copies of variables

William Brent william.brent at gmail.com
Tue Feb 19 09:51:43 PST 2008


It scares me that I'm only just now realizing how this works:

// make an array in 'a'
a = [1, 2, 3, 4];

// make a copy in a temporary variable by doing:
b = a;

// or
b = a.value;

// or
b = a.poll;

// alter the copy
b.remove(4);

// view the copy
b

// view the original (which i _thought_ would have been unchanged)
a


// but this approach works fine
a = [1, 2, 3, 4];

b = Array.new;

a.do{|item, i| b = b.add(item)};

b.remove(4);

b
a


So why does doing .remove on b affect a in the same way?  Obviously I'm
missing something fundamental here...  Is there a better way to make
temporary copies of a variable?


William




-- 
William Brent

"Great minds flock together"
Conflations: conversational idiom for the 21st century

www.conflations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.create.ucsb.edu/pipermail/sc-users/attachments/20080219/94204354/attachment.html 


More information about the sc-users mailing list