Hi -- On Sun, 8 May 2005, Dave Burt wrote: > "David A. Black" <dblack / wobblini.net> argued: >> On Sat, 7 May 2005, Dave Burt wrote: >>> And I think Austin's PDF::Writer example is one case where it's useful >>> (that >>> is, passing an object by reference into a method so the method can >>> replace >>> the object). >> >> It's a bit misleading to call it "passing by reference". In Ruby, all >> passing is by value. Many values happen to be references. If you >> have a Ref object, and pass it to a method, you are passing it by >> value-which-is-a-reference. That doesn't change, even if the object >> itself is of a class called Ref or Reference or Pointer, etc. >> >> I understand that when you then *do* something with that object, you >> are manipulating a second object, in a manner that emulates non-Ruby >> reference semantics. But still, as far as what's happening when you >> call the method with a Ref argument goes, it's still business as usual >> for Ruby. > > I think it's all business as usual for Ruby. It's very similar to passing in > an array with 1 element, then replacing that element. If the intention is > replacement of the object, I don't see how you distinguish those semantics > from "by reference" - the object itself (array or reference) is a reference. > Or more correctly, has a reference. What I mean is, for example, if you've got: def m(a); end x = "hi" a = [x] m(a) the mechanics and semantics of the sending of a to #m are not connected to what a actually is (an array containing a reference to a string). What your method does with the things it's passed doesn't play a role in the passing sequence. So if it's correct (as I think it is) to say that Ruby only does pass-by-value, I would not want to cloud that by saying, "unless the thing being passed is an object encapsulating someone's implementation of a reference-like behavior, in which case we might as well call it 'pass by reference' because we're going to do reference-like things with it." There's no actual such connection; what the object is used for is completely separate from the question of Ruby's argument-passing semantics. > Let's call it "pass by Ref" then, where Ref is my name for the container. I guess, but then do we have to say "pass by Array"? :-) David -- David A. Black dblack / wobblini.net