From: Chris White Date: 2011-08-13T19:34:51+09:00 Subject: Re: How to get the Name of a Variable On Aug 13, 2011, at 2:17 AM, Agent Mulder wrote: > Hello. > > When I call a function with an argument, I want to retrieve the NAME of > the original argument I passed into the funtion. In the code snippet > below, I want the last line of output to be: > > The NAME of the variable you passed in is: local_var > > instead of > > The NAME of the variable you passed in is: WHAT DO I NEED HERE? > > Thank you! > > > > def a_not_so_special_function(a) > puts "You are inside a_not_so_special_function().\n" > puts "The VALUE of the variable you passed in is: "+a > puts "The NAME of the variable you passed in is: "+"WHAT DO I NEED > HERE?" > end > > local_var="foo" > a_not_so_special_function(local_var) > > I suppose I'd have to ask why this is necessary. If you need a name associated with a value I'd recommend using a hash instead. Technically there might be a way be analyzing stack frames, but that would require access to the internals through the C API. Regards, Chris White http://www.twitter.com/cwgem