Richard wrote:
> Thanks for pointing me to that kernel method.  I've got to study the
> example(s) and construct a few of my own to apply it well.

Here's my own example, since I've never played with it before:

slim:~/Desktop gavinkistner$ ruby tmp.rb
Hello, Bob
Hello, Gavin



slim:~/Desktop gavinkistner$ ruby -d tmp.rb

Person#initialize called (line 3)
<end Person#initialize>

Person#initialize called (line 3)
<end Person#initialize>

Person#greet_first called (line 9)
--Person#greet called (line 6)
Hello, Bob
--<end Person#greet>
--Person#respond called (line 13)
----Person#greet called (line 6)
Hello, Gavin
----<end Person#greet>
--<end Person#respond>
<end Person#greet_first>

Object#recurse_down called (line 18)
--Object#recurse_down called (line 18)
----Object#recurse_down called (line 18)
------Object#recurse_down called (line 18)
--------Object#recurse_down called (line 18)
----------Object#recurse_down called (line 18)
------------Object#recurse_down called (line 18)
------------<end Object#recurse_down>
----------<end Object#recurse_down>
--------<end Object#recurse_down>
------<end Object#recurse_down>
----<end Object#recurse_down>
--<end Object#recurse_down>
<end Object#recurse_down>



slim:~/Desktop gavinkistner$ cat tmp.rb
class Person
  attr_reader :name
  def initialize( name )
    @name = name
  end
  def greet( someone )
    puts "Hello, #{someone.name}"
  end
  def greet_first( someone )
    greet( someone )
    someone.respond( self ) # Social Obligation!
  end
  def respond( someone )
    greet( someone )
  end
end

def recurse_down( count=6 )
  if count > 0
    recurse_down( count-1 )
  end
end

if $DEBUG
  set_trace_func lambda{ |event, file, line, id, binding, classname|
    $indent ||= 0

    # Only deal with events that occur inside this file
    return unless file == __FILE__

    # Only deal with calls to my functions
    case event
      when 'call'
        print $indent==0 ? "\n" : '--'*$indent
        puts "#{classname}##{id} called (line #{line})"
        $indent += 1

      when 'return'
        $indent -= 1
        print "--" * $indent
        puts "<end #{classname}##{id}>"

    end
  }
end

gk = Person.new( 'Gavin' )
bk = Person.new( 'Bob' )
gk.greet_first( bk )

recurse_down