From: Robert Klemme Date: 2007-09-11T17:46:07+09:00 Subject: Re: Accessing variable names in ruby 2007/9/7, Todd A. Jacobs : > I found myself trying to do a bit of ruby debugging, and was going crazy > trying to figure out how to display a variable's name instead of its > value in a string. There may be a more elegant way, but I found that > symbols did what I wanted: > > if $DEBUG > [:my_email, :my_resume, :my_logfile].each do |v| > $stderr.puts "DEBUG: #{v} = #{eval v.to_s}" > end > end > > Is there a better way? When you use %w you can easily use strings for this. I'd also use #inspect as it is generally better for debugging purposes: %w[my_email my_resume my_logfile].each do |v| $stderr.puts "DEBUG: #{v} = #{eval(v).inspect}" end if $DEBUG Kind regards robert