class Pry::Method::Disowned
A Disowned
Method
is one that's been removed from the class on which it was defined.
e.g. class C
def foo C.send(:undefine_method, :foo) Pry::Method.from_binding(binding) end
end
In this case we assume that the “owner” is the singleton class of the receiver.
This occurs mainly in Sinatra applications.
Attributes
name[R]
receiver[R]
Public Class Methods
new(receiver, method_name)
click to toggle source
Create a new Disowned
method.
@param [Object] receiver @param [String] method_name
# File lib/pry/method/disowned.rb, line 25 def initialize(receiver, method_name) @receiver = receiver @name = method_name @method = nil end
Public Instance Methods
method_missing(method_name, *args, &block)
click to toggle source
Raise a more useful error message instead of trying to forward to nil. rubocop:disable Style/MethodMissingSuper
# File lib/pry/method/disowned.rb, line 52 def method_missing(method_name, *args, &block) if method(:name).respond_to?(method_name) raise "Cannot call '#{method_name}' on an undef'd method." end method = Object.instance_method(:method_missing).bind(self) method.call(method_name, *args, &block) end
owner()
click to toggle source
Get the hypothesized owner of the method.
@return [Object]
# File lib/pry/method/disowned.rb, line 46 def owner class << receiver; self; end end
respond_to_missing?(method_name, include_private = false)
click to toggle source
rubocop:enable Style/MethodMissingSuper
Calls superclass method
Pry::Method#respond_to_missing?
# File lib/pry/method/disowned.rb, line 62 def respond_to_missing?(method_name, include_private = false) !method(:name).respond_to?(method_name) || super end
source?()
click to toggle source
Can we get the source for this method? @return [Boolean] false
# File lib/pry/method/disowned.rb, line 39 def source? false end
undefined?()
click to toggle source
Is the method undefined? (aka `Disowned`) @return [Boolean] true
# File lib/pry/method/disowned.rb, line 33 def undefined? true end