From: Charles Oliver Nutter Date: 2007-10-02T03:18:23+09:00 Subject: Re: a = Dog.new # a is not a pointer and not a reference? Austin Ziegler wrote: > On 9/29/07, SpringFlowers AutumnMoon wrote: >> Austin Ziegler wrote: >>> A variable in Ruby isn't like Java, PHP, C++, C, or even Pascal. >> Doesn't a Ruby variable behave the same way in Java, PHP5, C++, and >> Python? > > Didn't I just say that they aren't the same? > >> As long as I view Ruby as a pointer to an object, everything clicks. > > But that's exactly the *WRONG* way to look at it. In Pascal, Java, > C/C++, and possibly PHP5 (again, I don't know Python's semantics), a > variable takes up space. > > In Ruby, a variable doesn't contain anything. It doesn't contain an > address, it doesn't contain an object, it doesn't contain anything. It's > a label, a name, a sticky note attached to the object. In exactly the same way as Java variables don't take up space...except that they do. The same logic applies in both cases, and the analogy breaks down in the same way. A Java local variable does not take up space any differently than a Ruby local variable takes space; it's a slot in a stack frame. I'll stick by named slots being the most straightforward way to refer to Ruby (or Java) local variables. - Charlie