From: Robert Klemme Date: 2004-06-07T17:28:38+09:00 Subject: Re: When arg is a variable, can the variable's name be displayed? "Richard Lionheart" schrieb im Newsbeitrag news:9aKdnRz0R5mAj17dRVn-jg@comcast.com... > Hi, > > For debugging purposes, I'd like to write a routine to dump a variables > name and value, sort of like Object#inspect but different. I'd like to > write: > > def dumpv(var) > $stdin.print var.name + ' = "' + v.to_s + "\"\n" > $stdin.flush > end Btw: you didn't mean to use $stdin for printing, do you? def dumpv(varname, env) print varname.to_s, ' = "', eval(varname.to_s, env), "\"\n" end v1 = 'abc' dumpv :v1, binding Regards robert > v1 = 'abc' > dump(v1) # ==> v1 = "abc" > > v2 = 123 > dump(v2 ) # ==> v2 = "123" > > I recognize that this simple thing, if it worked for strings and numbers, > probably wouldn't work for some more complex types, but I'll worry about > that another day :-) > > And I acknowledge this isn't the world's greatest debugging tool, but it'll > help me develop some tool-writing skills in Ruby. > > TIA, > Richard > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.698 / Virus Database: 455 - Release Date: 6/4/2004 > >