From: Jim Weirich Date: 2004-04-03T07:22:11+09:00 Subject: Re: Variable names David King Landrith said: > Let me restate the question: > > Whenever a method is called on an object, one and only one symbol is > used to represent the object. That statement is incorrect. > Is there any way to determine which > symbol was representing the object at the time that the method was > invoked? Simple answer: NO Longer answer: Throw an exception and immediately catch it. Ask the exception for its backtrace and parse the file and line number from the backtrace (see ri backtrace for details). Then read the file in question and find the line number of the caller function. Then parse the line of code and guess at the variable name (if there is one). If you always call your type checking method in the form var.should_be(ClassName) # or whatever format you use then parsing the line of code is not a difficult problem. However, in the general case it is quite difficult. -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)