Is Ruby pass by reference or by value?
Working with Ruby, when passing an object to a method, how is the memory of this object handled?
Coming from a C background, I can think of several things which may be happening:
A copy of the memory associated with the according object and is made available to the method being called. In which case the modification of the object would only be reflected in the context of method being called, and not the calling method.
A reference to the memory of the object is passed the method being called (essentially a pointer). Hence any changes made by the object by the method being called or the calling method would be reflected in both contexts. As well, should this program be multithreaded, some kind of mechanism (mutex, semaphore, etc.) must be used to ensure mutually exclusive access to that memory performing write operations.
Something else I am unable to think of... maybe a memory model similar to that of Go... Pipes... MessagePassing...?
What is actually happening?