On Tue, Aug 05, 2003 at 04:56:50AM +0900, Roy Patrick Tan wrote:
> The problem is that in Ruby (and almost all modern imperative languages) 
> two variables can refer to the same object. So part of the solution is 
> never to use assignment except when creating an object (if you need a 
> copy of an object, clone it). But that still leaves us w parameter 
> passing, since a variable in the caller environment refers to an object 
> that is also referred to by a variable in the called method... so I 
> wanted to be able to clear the caller's variable.

But there may well not be any variable to clear:

    foo("hello")      # immediate object
    foo(MAX_ENTRIES)  # constant
    foo(x + 0)        # expression
    foo(bar())        # expression
    foo(Baz.new)      # expression

What gets passed in to the method as an argument is an object reference,
which may or may not have been stored in a local variable as an intermediate
stage.

"Never use assignment except when creating an object" also seems a strange
rule, as I think it would rule out "a = a + 1", for example.

If the actual issue is "object cannot be changed while it is in the
container" then maybe you should look at Object#freeze. If you 'dup' it out
of the container then the copy looses the frozen status.

Regards,

Brian.