[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: print out a variable's name and value?

Weirich, James

9/11/2003 10:38:00 PM

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

1 Answer

Ferenc Engard

9/12/2003 8:00:00 PM

0

"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