From: "Bartosz DziewoƄski" Date: 2011-08-14T01:23:16+09:00 Subject: Re: How to get the Name of a Variable *Please*, for the sake of human sanity, *do not* use the following code in *anything* serious *EVER*. This is only for demonstration purposes. def a_not_so_special_function(a) fname, line, _ = *caller[0].split(':') var_name = File.readlines('./'+fname)[line.to_i-1].match(/a_not_so_special_function[\(\s]([a-zA-Z0-9_]+)/)[1] 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: "+var_name end local_var="foo" a_not_so_special_function(local_var) In short - first line of the function uses a Kernel method 'caller' to figure out in which line of which file the function itself was called. Second lines uses this information to read the file, find the correct line and guess-parse it to find the variable name. This is going to fail if the function is called in any funny manner. And once again, please, do not use this code. If you don't want hashes, maybe it makes more sense to pass the actual name of variable to the function, and do some eval() magic to find out the value? This is definitely less brain-damaging solution than the above. -- Matma Rex