Class: Pry::Method::WeirdMethodLocator
- Defined in:
- lib/pry/method/weird_method_locator.rb
Overview
This class is responsible for locating the real ‘Pry::Method` object captured by a binding.
Given a ‘Binding` from inside a method and a ’seed’ Pry::Method object, there are primarily two situations where the seed method doesn’t match the Binding:
-
The Pry::Method is from a subclass
-
The Pry::Method represents a method of the same name while the original
was renamed to something else. For 1. we search vertically up the inheritance chain, and for 2. we search laterally along the object’s method table.
When we locate the method that matches the Binding we wrap it in Pry::Method and return it, or return nil if we fail.
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
-
.normal_method?(method, binding) ⇒ Boolean
Whether the given method object matches the associated binding.
- .weird_method?(method, binding) ⇒ Boolean
Instance Method Summary collapse
-
#find_method ⇒ Pry::Method?
The Pry::Method that matches the given binding.
-
#initialize(method, target) ⇒ WeirdMethodLocator
constructor
A new instance of WeirdMethodLocator.
-
#lost_method? ⇒ Boolean
Whether the Pry::Method is unrecoverable This usually happens when the method captured by the Binding has been subsequently deleted.
Constructor Details
#initialize(method, target) ⇒ WeirdMethodLocator
Returns a new instance of WeirdMethodLocator.
55 56 57 58 |
# File 'lib/pry/method/weird_method_locator.rb', line 55 def initialize(method, target) @method = method @target = target end |
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method.
49 50 51 |
# File 'lib/pry/method/weird_method_locator.rb', line 49 def method @method end |
#target ⇒ Object
Returns the value of attribute target.
50 51 52 |
# File 'lib/pry/method/weird_method_locator.rb', line 50 def target @target end |
Class Method Details
.normal_method?(method, binding) ⇒ Boolean
Whether the given method object matches the associated binding. If the method object does not match the binding, then it’s most likely not the method captured by the binding, and we must commence a search.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pry/method/weird_method_locator.rb', line 29 def normal_method?(method, binding) if method && method.source_file && method.source_range if binding.respond_to?(:source_location) binding_file, binding_line = binding.source_location else binding_file = binding.eval('__FILE__') binding_line = binding.eval('__LINE__') end (File.(method.source_file) == File.(binding_file)) && method.source_range.include?(binding_line) end rescue StandardError false end |
.weird_method?(method, binding) ⇒ Boolean
44 45 46 |
# File 'lib/pry/method/weird_method_locator.rb', line 44 def weird_method?(method, binding) !normal_method?(method, binding) end |
Instance Method Details
#find_method ⇒ Pry::Method?
Returns The Pry::Method that matches the given binding.
62 63 64 |
# File 'lib/pry/method/weird_method_locator.rb', line 62 def find_method find_method_in_superclass || find_renamed_method end |
#lost_method? ⇒ Boolean
Returns Whether the Pry::Method is unrecoverable This usually happens when the method captured by the Binding has been subsequently deleted.
69 70 71 |
# File 'lib/pry/method/weird_method_locator.rb', line 69 def lost_method? !!(find_method.nil? && renamed_method_source_location) end |