From: Mathew Johnston Date: 2002-06-07T05:28:02+09:00 Subject: Re: Getting a reference to the object which called a method On Thu, 2002-06-06 at 14:25, Paul Brannan wrote: > On Fri, Jun 07, 2002 at 03:44:19AM +0900, Mathew Johnston wrote: > > Is it possible to get the same effect as the following, but without > > having to pass self as an arguement? > > Yes, but all the solutions I know of are either slow or buggy (see > [ruby-talk:22963] for one such solution). > > Why do you want to do this, anyway? It doesn't sound like a good idea. > > Paul > Hmm :) What I'm trying to do is ensure that only the object which created another object can call it's methods. For example, object A instantiates object B. In object B's initialize method, I would set an object variable (@creator), referencing the object that called .new. On method calls, I would "raise 'Method called by non-creator' if [insert method to get ref to caller object].id == @creator.id" Is there another way to do this? Mat.