Hello Bill,

Monday, October 07, 2002, 7:12:31 PM, you wrote:

BT>    13. There is no standard, built-in deep copy in Ruby. One way to
BT>        achieve a similar effect is by serialization/marshalling.
BT> Because
BT>        in Ruby everything is a reference, be careful when you want to
BT>        "copy" objects, especially for objects that contain other
BT> objects
BT>        (such as arrays and hashes) and when the containment is more
BT> than
BT>        one level deep.

may be changed to:

ruby vars holds references to objects and '=' operator copies these
references:

a='x'
b=a
a << 'y'
# now both a and b points to string containing 'xy'

parameters to methods and closures also passed as references to actual
objects. in order to get new, unbounded copy of variable value, you
can use "dup" method:

a='x'
b=a.dup

it may be advisable to see whether you modify existing object or
create new one. as a rule of thumb is

1) methods ending with '!' modifies value in place
2) almost all other methods creates new objects
3) 'x+=b', 'x*=b' and other assignment operators is internally translated
into 'x=x+b' and so on, so these operators assign to x reference to
newly created object

-- 
Best regards,
 Bulat                            mailto:bulatz / integ.ru