From: matz@... (Yukihiro Matsumoto) Date: 2001-08-15T12:34:53+09:00 Subject: [ruby-talk:19754] Re: Why not?: Assigning to self Hi, In message "[ruby-talk:19749] Re: Why not?: Assigning to self" on 01/08/15, Ryo Furue writes: |Thanks for pointing that out here! In fact I knew that, but my |misunderstanding was that we could, within an instance method, make |self refer to a different object, as if | | void meth(void*& self) { // reference to pointer | void* s = new String("hello"); | self = s; // self now points to a String object. | } | | void* a = new Array(3.14, 2.9); | meth(a); | cout << *(String*)a << '\n'; // prints "hello". | |This much was my misunderstanding. Yes. There's no such thing like "reference (in C++)" in Ruby. I consider it harmful. |I think the correct interpretation |would be something like | | void meth(void* self) { // pointer | void* s = new String("hello"); | self = s; | // self now points to a String object, but the effect | // doesn't propagate to the caller. Would need to copy | // the String object into the memory pointed to by self. | } And I think you agree that it's useless. matz.