Class: Pry::Method::Disowned

Inherits:
Pry::Method show all
Defined in:
lib/pry/method.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?, all_from_class, all_from_common, all_from_obj, #doc, #doc_for_pry_method, #dynamically_defined?, from_binding, from_class, from_obj, from_str, instance_resolution_order, #is_a?, #method_name_from_first_line, #name_with_owner, #original_name, #pry_doc_info, #pry_method?, resolution_order, #respond_to?, safe_send, #signature, singleton_class, singleton_class_resolution_order, #source, #source_file, #source_line, #source_location, #source_range, #source_type, #super, #super_using_ancestors, #visibility, #wrapped_owner

Methods included from Helpers::DocumentationHelpers

#process_comment_markup, #process_rdoc, #process_yardoc, #process_yardoc_tag, #strip_comments_from_c_code, #strip_leading_hash_and_whitespace_from_ruby_comments, #strip_leading_whitespace

Methods included from RbxMethod

#core_code, #core_doc

Constructor Details

#initialize(receiver, method_name) ⇒ Disowned

Create a new Disowned method.

Parameters:

  • receiver (Object)
  • method_name (String)


517
518
519
# File 'lib/pry/method.rb', line 517

def initialize(receiver, method_name)
  @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.



541
542
543
544
# File 'lib/pry/method.rb', line 541

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.



511
512
513
# File 'lib/pry/method.rb', line 511

def name
  @name
end

#receiverObject (readonly)

Returns the value of attribute receiver.



511
512
513
# File 'lib/pry/method.rb', line 511

def receiver
  @receiver
end

Instance Method Details

#ownerObject

Get the hypothesized owner of the method.

Returns:



536
537
538
# File 'lib/pry/method.rb', line 536

def owner
  class << receiver; self; end
end

#source?Boolean

Can we get the source for this method?

Returns:

  • (Boolean)

    false



529
530
531
# File 'lib/pry/method.rb', line 529

def source?
  false
end

#undefined?Boolean

Is the method undefined? (aka Disowned)

Returns:

  • (Boolean)

    true



523
524
525
# File 'lib/pry/method.rb', line 523

def undefined?
  true
end