From: David Alan Black Date: 2002-08-01T03:03:47+09:00 Subject: Re: How to Emulate C/C++ Pointer/Reference in Ruby? Hello -- On Thu, 1 Aug 2002, William Djaja Tjokroaminata wrote: > Thanks for all the responses. For efficiency purposes (because the file > is accessed so often), probably I prefer 2) rather than 3). Depending on > the implementation, I guess, 1) will be somewhere between 2) and 3). > > However, this is only for the one specific example. I guess, then, indeed > there is no way to emulate pointer in Ruby. I used Perl not for long > before I switched to Ruby. If I am not mistaken, in Perl there is stuff > called reference. [My understanding, subject to corrective intervention] The thing is that in Ruby, every variable holds a reference to some object, and variables are all at the same level of remove from their objects. (This is probably wrong or different for immutables, but I'm excluding them for the moment.) So if you have: a = [1,2,3] there's no way to get a "reference to a", the way you can have "pointer to pointer [to pointer [...]]" in C. What you *can* have is other references to the same object: b = a So in Ruby, rather than the infinitely regressing line of pointer relationships, you get something more like a circle of references, all equidistant from the object and all terminal (in the sense that they're at the furthest possible level away from the object). David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav