Hmm. So there is no built-in way of doing this? What about lambdas? Should the result be nil, or stay silent? irb(main):001:0> def my_name_is irb(main):002:1> caller[0].split( /:in /).last.gsub( /[\'|\`]/, '' ) irb(main):003:1> end => nil irb(main):004:0> 1.upto(3){ |i| irb(main):005:1* p i irb(main):006:1> my_name_is irb(main):007:1> } 1 2 3 => 1 irb(main):008:0> even more interesting is irb(main):011:0> 1.upto(3){ |i| irb(main):012:1* p i irb(main):013:1> p my_name_is irb(main):014:1> } 1 "irb_binding" 2 "irb_binding" 3 "irb_binding" => 1 irb(main):015:0> Cheers! -CWS On Mon, 19 Jul 2004 04:28:10 +0900, James Britt <jamesunderbarb / neurogami.com> wrote: > > Here is an example based on something I believe Rick Kilmer posted here > some time ago, plus some additional neat Ruby magic for dynamic code > tracing (also from Rich, I think, but I might be wrong on that). > > # Eval a code block using the original context of the variables > def trace( &block ) > expr = block.call > puts "trace: #{expr} = #{eval(expr, block)}" > end > > # Get the name of the immediate caller > def my_name_is > caller[0].split( /:in /).last.gsub( /[\'|\`]/, '' ) > end > > # An example method to demo the previous two helper methods > def something( z ) > puts "My name is \"#{my_name_is}\"" > x = 5 > y = 7 > trace { "x + y + z" } # Show this to Java(tm) fans. > end > > # Simple method to demo nested calls to my_name_is > # Not quite unit testing, I know ... > def foo > puts "My name is \"#{my_name_is}\"" > something( 12 ) > end > > something 10 > foo > > > James > >