From: wangqianpku@... Date: 2007-10-05T10:50:03+09:00 Subject: Re: a = Dog.new # a is not a pointer and not a reference? On Sep 30, 1:16 am, 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. > > (Pointers and References discussed in > > http://en.wikipedia.org/wiki/Reference_%28computer_science%29http://en.wikipedia.org/wiki/Reference_%28C%2B%2B%29 > > ) > -- > Posted viahttp://www.ruby-forum.com/. Yes! You're right. It's really not "reference" or "value" or "pointer" in c++ sense. Some body calls it "reference to object" or something else. Anyway, if you want to use conceptions in c++ sense to describe it. It works like (i said somewhere before).... when it's used as a left value, it works like a pointer, which means the variable doesn't have the object. it only points to the object. when it's used as a right value, it dereference automatically.