From: Jeff Mitchell Date: 2004-06-06T22:03:17+09:00 Subject: Re: When arg is a variable, can the variable's name be displayed? --- Richard Lionheart wrote: > 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: > I put the following on http://www.rubygarden.org/ruby?OneLiners def show(&block) printf("%-25s>> %s\n", expr = block.call, eval(expr, block.binding).inspect) end Example: show {%{ a = [1,2,3] }} ; show {%{ a.slice(1,2) }} ; show {%{ a.map { |x| x**3 } }} produces: a = [1,2,3] >> [1, 2, 3] a.slice(1,2) >> [2, 3] a.map { |x| x**3 } >> [1, 8, 27] __________________________________ Do you Yahoo!? Friends. Fun. Try the all-new Yahoo! Messenger. http://messenger.yahoo.com/