Print out a variable's name and value?

Ferenc Engard [mailto:ferenc@engard.hu] writes:

I want a comfortable debug function to which I can pass a
variable, and it writes out the variable’s name and value.

Try this:

def dbg(&block)
varname = block.call.to_s
puts “DBG: #{varname} = #{eval(varname,block)}”
end

x = 10
dbg{:x} # IMPORTANT! Notice curly braces.

···


– Jim Weirich / Compuware
– FWP Capture Services
– Phone: 859-386-8855

“Weirich, James” wrote:

Ferenc Engard [mailto:ferenc@engard.hu] writes:

I want a comfortable debug function to which I can pass a
variable, and it writes out the variable’s name and value.

Try this:

def dbg(&block)
varname = block.call.to_s
puts “DBG: #{varname} = #{eval(varname,block)}”
end

x = 10
dbg{:x} # IMPORTANT! Notice curly braces.

WOW! Nice. :-))))

Circum