From: Kaspar Schiess Date: 2004-06-06T23:40:43+09:00 Subject: Re: When arg is a variable, can the variable's name be displayed? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello Richard, Close but no cigar: def debug(s) set_trace_func proc { |event, file, line, id, b, classname| if (event == 'return') begin puts "#{s} = #{eval(s, b).inspect}" rescue NameError puts "#{s} is undefined" end end set_trace_func(nil) } end require 'test/unit' class DebugTest < Test::Unit::TestCase def puts(str) @@last = str end def test_local a = [1,2,3] debug 'a' assert_equal 'a = [1, 2, 3]', @@last end def test_instance @a = [1,2,3] debug '@a' assert_equal '@a = [1, 2, 3]', @@last end def test_class @@a = [1,2,3] debug '@@a' assert_equal '@@a = [1, 2, 3]', @@last end def test_global $a = [1,2,3] debug '$a' assert_equal '$a = [1, 2, 3]', @@last end end best regards, - -- kaspar semantics & semiotics code manufacture www.tua.ch/ruby -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFAwy2xFifl4CA0ImQRAtA2AJ0YzhaaRmwac+berljlc+7FetqrAwCfXd8A SbQ6siHcMYw4hcfTsBJkNJ8= =IdAe -----END PGP SIGNATURE----- -- kaspar semantics & semiotics code manufacture www.tua.ch/ruby