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 2. 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, b) ⇒ Boolean
Whether the given method object matches the associated binding.
- .weird_method?(method, b) ⇒ Boolean
Instance Method Summary collapse
-
#get_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.
45 46 47 |
# File 'lib/pry/method/weird_method_locator.rb', line 45 def initialize(method, target) @method, @target = method, target end |
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method.
39 40 41 |
# File 'lib/pry/method/weird_method_locator.rb', line 39 def method @method end |
#target ⇒ Object
Returns the value of attribute target.
40 41 42 |
# File 'lib/pry/method/weird_method_locator.rb', line 40 def target @target end |
Class Method Details
.normal_method?(method, b) ⇒ 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.
28 29 30 31 32 |
# File 'lib/pry/method/weird_method_locator.rb', line 28 def normal_method?(method, b) method && (method.source_file && method.source_range rescue false) && File.(method.source_file) == File.(b.eval('__FILE__')) && method.source_range.include?(b.eval('__LINE__')) end |
.weird_method?(method, b) ⇒ Boolean
34 35 36 |
# File 'lib/pry/method/weird_method_locator.rb', line 34 def weird_method?(method, b) !normal_method?(method, b) end |
Instance Method Details
#get_method ⇒ Pry::Method?
Returns The Pry::Method that matches the given binding.
51 52 53 |
# File 'lib/pry/method/weird_method_locator.rb', line 51 def get_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.
58 59 60 |
# File 'lib/pry/method/weird_method_locator.rb', line 58 def lost_method? !!(get_method.nil? && renamed_method_source_location) end |