Class: Pry::Method::Disowned

Inherits:
Pry::Method show all
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

Instance Method Summary collapse

Methods inherited from Pry::Method

#==, #alias?, #aliases, all_from_class, all_from_common, all_from_obj, #bound_method?, #c_source, #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?, #method_name_from_first_line, #name_with_owner, #original_name, #pry_doc_info, #pry_method?, #redefine, resolution_order, #respond_to?, #ruby_source, #signature, singleton_class_of, singleton_class_resolution_order, #singleton_method?, singleton_method_definition?, #source, #source_file, #source_line, #source_range, #source_type, #super, #super_using_ancestors, #unbound_method?, #visibility, #wrapped, #wrapped_owner

Methods included from Helpers::BaseHelpers

colorize_code, #colorize_code, command_dependencies_met?, #command_dependencies_met?, context_from_object_path, #context_from_object_path, find_command, #find_command, heading, #heading, #highlight, highlight, jruby?, #jruby?, jruby_19?, #jruby_19?, mri?, #mri?, #mri_19?, mri_19?, mri_20?, #mri_20?, #mri_21?, mri_21?, #not_a_real_file?, not_a_real_file?, #rbx?, rbx?, #safe_send, safe_send, silence_warnings, #silence_warnings, #stagger_output, stagger_output, use_ansi_codes?, #use_ansi_codes?, windows?, #windows?, windows_ansi?, #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, get_comment_content, process_comment_markup, #process_comment_markup, #process_rdoc, process_rdoc, #process_yardoc, process_yardoc, process_yardoc_tag, #process_yardoc_tag, #strip_comments_from_c_code, strip_comments_from_c_code, #strip_leading_whitespace, strip_leading_whitespace

Constructor Details

#initialize(receiver, method_name, binding = nil) ⇒ Disowned

Create a new Disowned method.

Parameters:

  • receiver (Object)
  • method_name (String)


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

#nameObject (readonly)

Returns the value of attribute name



17
18
19
# File 'lib/pry/method/disowned.rb', line 17

def name
  @name
end

#receiverObject (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

#ownerObject

Get the hypothesized owner of the method.

Returns:



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?

Returns:

  • (Boolean)

    false



35
36
37
# File 'lib/pry/method/disowned.rb', line 35

def source?
  false
end

#undefined?Boolean

Is the method undefined? (aka Disowned)

Returns:

  • (Boolean)

    true



29
30
31
# File 'lib/pry/method/disowned.rb', line 29

def undefined?
  true
end