class DEBUGGER__::ObjectTracer - debug: Ruby Standard Library Documentation

# class DEBUGGER__::ObjectTracer

### Public Class Methods

new(ui, obj_id, obj_inspect, **kw) click to toggle source
Calls superclass method `DEBUGGER__::Tracer::new`

    # File debug-1.10.0/lib/debug/tracer.rb, line 169
    def initialize ui, obj_id, obj_inspect, **kw
      @obj_id = obj_id
      @obj_inspect = obj_inspect
      super(ui, **kw)
      @key = [@type, @obj_id, @pattern, @into].freeze
    end

### Public Instance Methods

colorized_obj_inspect() click to toggle source

    # File debug-1.10.0/lib/debug/tracer.rb, line 180
    def colorized_obj_inspect
      colorize_magenta(@obj_inspect)
    end

description() click to toggle source

    # File debug-1.10.0/lib/debug/tracer.rb, line 176
    def description
      " for #{@obj_inspect}"
    end

setup() click to toggle source

    # File debug-1.10.0/lib/debug/tracer.rb, line 184
    def setup
      @tracer = TracePoint.new(:a_call){|tp|
        next if skip?(tp)

        if M_OBJECT_ID.bind_call(tp.self) == @obj_id
          klass = tp.defined_class
          method = tp.method_id
          method_info =
            if klass.singleton_class?
              if tp.self.is_a?(Class)
                ".#{method} (#{klass}.#{method})"
              else
                ".#{method}"
              end
            else
              "##{method} (#{klass}##{method})"
            end

          out tp, " #{colorized_obj_inspect} receives #{colorize_blue(method_info)}"
        elsif !tp.parameters.empty?
          b = tp.binding
          method_info = colorize_blue(minfo(tp))

          tp.parameters.each{|type, name|
            next unless name

            colorized_name = colorize_cyan(name)

            case type
            when :req, :opt, :key, :keyreq
              if b.local_variable_get(name).object_id == @obj_id
                out tp, " #{colorized_obj_inspect} is used as a parameter #{colorized_name} of #{method_info}"
              end
            when :rest
              next if name == :"*"

              ary = b.local_variable_get(name)
              ary.each{|e|
                if e.object_id == @obj_id
                  out tp, " #{colorized_obj_inspect} is used as a parameter in #{colorized_name} of #{method_info}"
                end
              }
            when :keyrest
              next if name == :'**'
              h = b.local_variable_get(name)
              h.each{|k, e|
                if e.object_id == @obj_id
                  out tp, " #{colorized_obj_inspect} is used as a parameter in #{colorized_name} of #{method_info}"
                end
              }
            end
          }
        end
      }
    end