Class: Pry::Method::Disowned
- Inherits:
-
Pry::Method
- Object
- Pry::Method
- Pry::Method::Disowned
- Defined in:
- lib/pry/method/disowned.rb
Overview
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.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
-
#initialize(receiver, method_name, binding = nil) ⇒ Disowned
constructor
Create a new Disowned method.
-
#method_missing(meth_name, *args, &block) ⇒ Object
Raise a more useful error message instead of trying to forward to nil.
-
#owner ⇒ Object
Get the hypothesized owner of the method.
-
#source? ⇒ Boolean
Can we get the source for this method?.
-
#undefined? ⇒ Boolean
Is the method undefined? (aka ‘Disowned`).
Methods inherited from Pry::Method
#==, #alias?, #aliases, all_from_class, all_from_common, all_from_obj, #bound_method?, #comment, #doc, #dynamically_defined?, from_binding, from_class, from_obj, from_str, instance_method_definition?, instance_resolution_order, #is_a?, lookup_method_via_binding, method_definition?, #name_with_owner, #original_name, #pry_method?, #redefine, resolution_order, #respond_to?, #signature, singleton_class_of, singleton_class_resolution_order, #singleton_method?, singleton_method_definition?, #source, #source_file, #source_line, #source_range, #source_type, #super, #unbound_method?, #visibility, #wrapped, #wrapped_owner
Methods included from Helpers::BaseHelpers
colorize_code, command_dependencies_met?, find_command, heading, highlight, jruby?, jruby_19?, mri?, mri_19?, mri_20?, mri_21?, mri_2?, not_a_real_file?, rbx?, #safe_send, safe_send, silence_warnings, stagger_output, use_ansi_codes?, windows?, windows_ansi?
Methods included from CodeObject::Helpers
#c_method?, #command?, #module_with_yard_docs?, #real_method_object?
Methods included from Helpers::DocumentationHelpers
get_comment_content, process_comment_markup, process_rdoc, process_yardoc, process_yardoc_tag, strip_comments_from_c_code, strip_leading_whitespace
Constructor Details
#initialize(receiver, method_name, binding = nil) ⇒ Disowned
Create a new Disowned method.
23 24 25 |
# File 'lib/pry/method/disowned.rb', line 23 def initialize(receiver, method_name, binding=nil) @receiver, @name = receiver, method_name end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth_name, *args, &block) ⇒ Object
Raise a more useful error message instead of trying to forward to nil.
47 48 49 50 |
# File 'lib/pry/method/disowned.rb', line 47 def method_missing(meth_name, *args, &block) raise "Cannot call '#{meth_name}' on an undef'd method." if method(:name).respond_to?(meth_name) Object.instance_method(:method_missing).bind(self).call(meth_name, *args, &block) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/pry/method/disowned.rb', line 17 def name @name end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
17 18 19 |
# File 'lib/pry/method/disowned.rb', line 17 def receiver @receiver end |
Instance Method Details
#owner ⇒ Object
Get the hypothesized owner of the method.
42 43 44 |
# File 'lib/pry/method/disowned.rb', line 42 def owner class << receiver; self; end end |
#source? ⇒ Boolean
Can we get the source for this method?
35 36 37 |
# File 'lib/pry/method/disowned.rb', line 35 def source? false end |
#undefined? ⇒ Boolean
Is the method undefined? (aka ‘Disowned`)
29 30 31 |
# File 'lib/pry/method/disowned.rb', line 29 def undefined? true end |