On Sep 29, 2007, at 1:16 PM, SpringFlowers AutumnMoon wrote: > when we say > > a = Dog.new("lulu") > > Now a is not really a pointer, because we don't need to dereference it > to use it, like > > (*a).color = "red" > a->color = "red" > > When we use a.color, it is like a reference in C++ implicitly > dereference it and use its attributes. > > But then a is not really a reference (like C++), because we can say > > a = nil or a = Dog.new("woofy") > > and now a points to some where else. With reference, once a reference > is set, it cannot point to some where else (in C++). > > So it is kind of a mixture of pointer and reference? > > Or, we can think of it as a pointer, and then think of "." as the "->" > in C++. > > In that case, we can say that a is a pointer and not a reference. > > And it seems the same way in Java, Python, and PHP5. I think it best to think of a Ruby variable as holding a reference to an object. Ruby's reference semantics are different from C++'s, but IMO more mainstream. C++'s reference semantics are peculiar, to say the least, and perhaps even unique [*]. Ruby's variable semantics are simple and clean when compared to C++, so I recommend forgetting about making such comparisons. Regards, Morton [*] Betrand Meyer of Eiffel fame has often made fun of C++'s reference semantics. He has claimed they are beyond the understanding of mere mortals. He is joking, of course.