123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::ObjectTracer

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Tracer
Instance Chain:
Inherits: DEBUGGER__::Tracer
Defined in: lib/debug/tracer.rb

Class Method Summary

Instance Attribute Summary

Tracer - Inherited

Instance Method Summary

Tracer - Inherited

Color - Included

#color_pp

See additional method definition at line 50.

#colored_inspect,
#colorize

See additional method definition at line 36.

#colorize_blue,
#colorize_code

See additional method definition at line 79.

#colorize_cyan, #colorize_dim, #colorize_magenta,
#irb_colorize

See additional method definition at line 27.

#with_inspection_error_guard

SkipPathHelper - Included

Constructor Details

.new(ui, obj_id, obj_inspect, **kw) ⇒ ObjectTracer

[ GitHub ]

  
# File '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

Instance Method Details

#colorized_obj_inspect

[ GitHub ]

  
# File 'lib/debug/tracer.rb', line 180

def colorized_obj_inspect
  colorize_magenta(@obj_inspect)
end

#description

[ GitHub ]

  
# File 'lib/debug/tracer.rb', line 176

def description
  " for #{@obj_inspect}"
end

#setup

[ GitHub ]

  
# File '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