From: Alex Young Date: 2006-07-22T22:01:51+09:00 Subject: Re: Assigning blame? Ben Zealley wrote: > 'allo > > Say I have two classes: > > class Bloke > attr_reader :name > def sellSoul(aDemon) > aDemon.buySoul(self) > end > end > > class Demon > def buySoul(aBloke) > # if aBloke called the method, OK. Else, tell them where to go. > puts("I bought #{aBloke.name}'s soul!") > end > end > > Tim = Bloke.new > Tim.name = "Tim" > Satan = Demon.new > Tim.sellSoul(Satan) > > I would like the buySoul method to work only if the Bloke calling it is > the same instance of Bloke named, but I can't find any way to determine > what object called a given method. Does anyone have a suggestion? Not quite what you're after, but it has the same effect: make sellSoul a private method, so that it's only possible (without #send contortions) for Tim to call sellSoul on self. Other than that, I think you'll be into checking object_ids against constants at the top execution level, which isn't particularly useful. You could pass the binding to buySoul, I guess, but that's just as nasty. -- Alex