Class: PryDebug::MethodBreakpoint

Inherits:
Struct
  • Object
show all
Includes:
ConditionalBreakpoint
Defined in:
lib/pry_debug/method_breakpoint.rb

Instance Attribute Summary collapse

Attributes included from ConditionalBreakpoint

#condition

Instance Method Summary collapse

Instance Attribute Details

#class_methodObject Also known as: class_method?

Returns the value of attribute class_method

Returns:

  • (Object)

    the current value of class_method



2
3
4
# File 'lib/pry_debug/method_breakpoint.rb', line 2

def class_method
  @class_method
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/pry_debug/method_breakpoint.rb', line 2

def id
  @id
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



2
3
4
# File 'lib/pry_debug/method_breakpoint.rb', line 2

def klass
  @klass
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/pry_debug/method_breakpoint.rb', line 2

def name
  @name
end

Instance Method Details

#actual_classObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/pry_debug/method_breakpoint.rb', line 64

def actual_class
  # this method uses Module#=== to be BasicObject safe
  @actual_class ||= klass.split('::').inject(Object) do |mod, const_name|
    if (Module === mod) && mod.const_defined?(const_name)
      mod.const_get const_name
    else
      break
    end
  end

  (Module === @actual_class) ? @actual_class : nil
end

#at_method?(other_class, other_name, other_class_method) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pry_debug/method_breakpoint.rb', line 7

def at_method?(other_class, other_name, other_class_method)
  return false unless Module === other_class

  if klass == other_class.to_s && name == other_name &&
      class_method == other_class_method
    true # exactly the same parameters
  else # find out if the method we are referring to is the same as the one
       # that was called.
    if klass = actual_class
      other_method = if other_class_method && has_class_method?(other_class, other_name)
                       (class << other_class; self; end).instance_method(other_name)
                     elsif !other_class_method && has_instance_method?(other_class, other_name)
                       other_class.instance_method(other_name)
                     end

      if referred_method && other_method
        singleton_class = (class << klass; self; end)
        (other_class < klass || other_class == klass ||
         (singleton_class == other_class || singleton_class < klass)) &&
          ((referred_method == other_method) ||
           (referred_method.name  == other_method.name &&
            referred_method.owner == other_method.owner))
      else
        false
      end
    else
      false # can't get information about the class
    end
  end
end

#has_class_method?(klass, method) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
86
87
# File 'lib/pry_debug/method_breakpoint.rb', line 83

def has_class_method?(klass, method)
  (klass.private_methods + klass.methods).any? do |m|
    m.to_s == method
  end
end

#has_instance_method?(klass, method) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/pry_debug/method_breakpoint.rb', line 77

def has_instance_method?(klass, method)
  (klass.private_instance_methods + klass.instance_methods).any? do |m|
    m.to_s == method
  end
end

#is_at?(other_class, other_name, other_class_method, binding) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/pry_debug/method_breakpoint.rb', line 38

def is_at?(other_class, other_name, other_class_method, binding)
  at_method?(other_class, other_name, other_class_method) && super(binding)
end

#method_nameObject



50
51
52
# File 'lib/pry_debug/method_breakpoint.rb', line 50

def method_name
  klass + separator + name
end

#referred_methodObject



54
55
56
57
58
59
60
61
62
# File 'lib/pry_debug/method_breakpoint.rb', line 54

def referred_method
  if klass = actual_class
    @referred_method ||= if class_method? && has_class_method?(klass, name)
                           (class << klass; self; end).instance_method(name)
                         elsif !class_method && has_instance_method?(klass, name)
                           klass.instance_method(name)
                         end
  end
end

#separatorObject



46
47
48
# File 'lib/pry_debug/method_breakpoint.rb', line 46

def separator
  class_method ? "." : "#"
end

#to_sObject



42
43
44
# File 'lib/pry_debug/method_breakpoint.rb', line 42

def to_s
  "breakpoint #{id} at #{method_name}#{super}"
end