Project

General

Profile

Actions

Bug #8817

closed

Method#owner on prepended classes is an instance rather than Class/Method

Added by soulcutter (Bradley Schaefer) over 10 years ago. Updated about 10 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
[ruby-core:56799]

Description

rdoc indicates that Method#owner will return a class or module that defines a method. http://www.ruby-doc.org/core-2.0/Method.html#method-i-owner

For classes that have prepended modules, the owner is actually an instance.

Example code:

module Mod; end

class Foo
prepend Mod
def foo; 'foo'; end
end

owner = Foo.instance_method(:foo).owner
puts "Method#owner on a prepended class instance_method: #{owner.inspect}" #=> #Foo:0x007fd34dfd3ea0
puts "Class?: #{owner.is_a? Class}" #=> false
puts "Module?: #{owner.is_a? Module}" #=> false

This had the effect of breaking stubbing in rspec (https://github.com/rspec/rspec-mocks/pull/385) , though a workaround is that the expected Class/Module can be retrieved by asking for the returned object's class.


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #7993: owner of methods defined after using Module#prependClosed03/01/2013Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0