Sha256: ddada83cc2f858f7b66ed83961cc33aa3523b800fa68bb343a7040f42edc8dd5

Contents?: true

Size: 1.76 KB

Versions: 6796

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

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)
        @receiver = receiver
        @name = 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.
      # rubocop:disable Style/MethodMissingSuper
      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
      # rubocop:enable Style/MethodMissingSuper

      def respond_to_missing?(method_name, include_private = false)
        !method(:name).respond_to?(method_name) || super
      end
    end
  end
end

Version data entries

6,796 entries across 6,792 versions & 31 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/pry-0.13.1/lib/pry/method/disowned.rb
cybrid_api_bank_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_organization_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_id_ruby-0.123.145 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_bank_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_id_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_organization_ruby-0.123.144 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
ory-client-1.16.1 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
ory-client-1.16.0 vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/method/disowned.rb
cybrid_api_bank_ruby-0.123.143 vendor/bundle/ruby/3.3.0/gems/pry-0.14.2/lib/pry/method/disowned.rb