class RSpec::Mocks::InstanceMethodStasher

def method_owned_by_klass?

def method_owned_by_klass?
  owner = @klass.instance_method(@method).owner
  # On Ruby 2.0.0+ the owner of a method on a class which has been
  # `prepend`ed may actually be an instance, e.g.
  # `#<MyClass:0x007fbb94e3cd10>`, rather than the expected `MyClass`.
  owner = owner.class unless Module === owner
  # On some 1.9s (e.g. rubinius) aliased methods
  # can report the wrong owner. Example:
  # class MyClass
  #   class << self
  #     alias alternate_new new
  #   end
  # end
  #
  # MyClass.owner(:alternate_new) returns `Class` when incorrect,
  # but we need to consider the owner to be `MyClass` because
  # it is not actually available on `Class` but is on `MyClass`.
  # Hence, we verify that the owner actually has the method defined.
  # If the given owner does not have the method defined, we assume
  # that the method is actually owned by @klass.
  owner == @klass || !(method_defined_on_klass?(owner))
end