From: Charles Oliver Nutter Date: 2007-10-01T11:17:29+09:00 Subject: Re: a = Dog.new # a is not a pointer and not a reference? Austin Ziegler wrote: > No, I don't think that's a valid comparison because a void* still > takes up space -- it's a location -- in C++. That is, I can > legitimately do: > > void* a = &5; > void* b = &a; > > It's *important* for people to understand deeply that Ruby variables > take up no space -- they're labels. If I call something a cat and you > call that same something 'Fluffy', we're still referring to the same > animal, but neither of our names for that animal can easily be > referred to by another name. > > Ruby variables are "wafer-thin". They're, as I said, just sticky notes > that can be moved around at will. It's the *objects* that take up the > space. Ruby variables take up just as much space, they just do it in the call stack rather than on the heap. They don't move around, you can't define new ones in a given scope after it's been parsed and activated (except for a few oddities in eval), and they have specific locations in memory for the duration of a given activation. Each variable name represents a slot in the local scope of the method activation. Some slots are named, some aren't; flip-flops, for example, get anonymous slots. Ruby variables hold the value of an object reference. If you re-assign them, you are setting them to a different object reference. If you retrieve them, you're getting an object reference which you can then pass by value or use to invoke methods. - Charlie