From: Austin Ziegler Date: 2005-05-05T06:55:15+09:00 Subject: Re: object reference handle (like perl's reference to scalar) On 5/4/05, Eric Mahurin wrote: > In ruby, is there a way to get a handle of an object reference? In > perl, this is the \ operator: > > $x = 1; # \$x is a handle to change $x > $a = [1,2,3]; # \$a-> [1] is a handle to change an element in $a > > As far as I can tell, the closest that Ruby has to this is a > symbol. But, this only works for object references that have an > associated variable name. For example, there is no symbol > associated with an element of an array (or hash). What are you trying to do? There is no equivalent to what you want in Ruby, but in most cases, it's not necessary. A little bit of rethinking, on the other hand, is necessary. There is no way to do the following: a = [1, 2, 3] x = a[1] x = 4 # a == [1, 4, 3] Variables in Ruby are simply labels for object references. They are not objects themselves. In Ruby, variables are transient names -- they are effectively "weightless" and take up no space (effectively). In Perl and C-like languages, variables themselves take up space on the call stack and may refer to other places on the heap. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca