From: Jim Weirich Date: 2003-06-01T06:36:53+09:00 Subject: Re: newbie questions On Sat, 2003-05-31 at 16:45, Steven Ketcham wrote: > I am probably confusing concepts but in C++ you can pass a parameter by reference, pointer or value. Copy constructors, > variable scope and things like that are very important to track. If I pass a complex object by value to a function, the copy > of the object will automatically run it's destructor when the function > returns. This could be devasting when working with file or database handles. > > How are objects handled when passed to a function with Ruby? You have a "shoebox" mentally. In other words, you are thinking of variables as "showboxes" in which you put values. This mental model works well with C++, where a constructor is run when a shoebox (variable) is created and a destructor is run when the shoebox is destroyed. Copy contructors and assigment operators all deal with the coping of the contents of one shoebox to another. When dealing with Ruby, forget shoeboxes. Variables are names that are attached (bound) to values. Names can be rebound at will and multiple names can be bound to any one object. See http://www.rubygarden.org/ruby?VariablesAndObjects for a longer rant on this topic. -- -- Jim Weirich jweirich@one.net http://jimweirich.umlcoop.net --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)