From: Mikkel Damsgaard Date: 2001-09-24T04:45:58+09:00 Subject: [ruby-talk:21610] Re: Please translate this easy snip of C++ to Ruby > Phlip > Ruby Users: > > Ogle this awesome snip of C++: > > #define TRACE_(x) cout << #x ": " << x << endl > > When you use that like this: > > TRACE_(y + z); > TRACE_(strAnimals); > TRACE_(__LINE__); > > the program emits this: > > y + z: 12 > strAnimals: Lemmings > __LINE__: 69 > > Mighty healthy and easy to write debug statements with, huh? > Saves a lot of > keystrokes, huh? > > How do I do that, just as easy to call (meaning without extra > "" quotes or > anything), in Ruby? > The closest I come is this: def trace(expr) print expr + "=", eval(expr,TOPLEVEL_BINDING) puts end g = 2 trace("0") trace("1+2") trace("17+18") trace("g") But you dont get rid of the "'s (But who cares anyway ....) > -- > Phlip phlip_cpp@my-deja.com > ============ http://c2.com/cgi/wiki?PhlIp ============ > -- In the beginning, God distinguished heaven and earth --