Sha256: e6b419b0a2d25539a8d8917acba6c0e7ae4442d6d55b10b415569f28717fd085

Contents?: true

Size: 1.45 KB

Versions: 24

Compression:

Stored size: 1.45 KB

Contents

class Pry
  class Method
    # 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.
    class Disowned < Method
      attr_reader :receiver, :name

      # Create a new Disowned method.
      #
      # @param [Object] receiver
      # @param [String] method_name
      def initialize(receiver, method_name, binding=nil)
        @receiver, @name = receiver, method_name
        @method = nil
      end

      # Is the method undefined? (aka `Disowned`)
      # @return [Boolean] true
      def undefined?
        true
      end

      # Can we get the source for this method?
      # @return [Boolean] false
      def source?
        false
      end

      # Get the hypothesized owner of the method.
      #
      # @return [Object]
      def owner
        class << receiver; self; end
      end

      # Raise a more useful error message instead of trying to forward to nil.
      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
    end
  end
end

Version data entries

24 entries across 24 versions & 8 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
xaiml-0.1.3 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
xaiml-0.1.2 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
xaiml-0.1.1 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
xaiml-0.1.0 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
monero_wallet_gen-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
sb_prime_table-0.1.1 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
sb_prime_table-0.1.0 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/method/disowned.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/method/disowned.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/method/disowned.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/method/disowned.rb
pry-0.11.3 lib/pry/method/disowned.rb
pry-0.11.3-java lib/pry/method/disowned.rb
pry-0.11.2 lib/pry/method/disowned.rb
pry-0.11.2-java lib/pry/method/disowned.rb
tdiary-5.0.6 vendor/bundle/gems/pry-0.11.0/lib/pry/method/disowned.rb
pry-0.11.1 lib/pry/method/disowned.rb
pry-0.11.1-java lib/pry/method/disowned.rb
pry-0.11.0 lib/pry/method/disowned.rb
pry-0.11.0-java lib/pry/method/disowned.rb