Project

General

Profile

Bug #9526

Method#owner returns wrong owner if using prepend.

Added by Kaneko Yuichiro over 2 years ago. Updated over 2 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
ruby -v:
ruby-2.0.0-p353 [ x86_64 ] & ruby-2.1.0 [ x86_64 ]
[ruby-dev:47975]

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


module MyMod
def x(y)
super(y*y)
end
end

class Blah
def x(y)
y + 1
end
prepend MyMod
end

Blah.new.method(:x).owner
# => MyMod


In this case, a class or module that defines a method is Blah.
So I think Blah.new.method(:x).owner should return Blah.

History

#1 [ruby-dev:47976] Updated by Shugo Maeda over 2 years ago

Kaneko Yuichiro wrote:

In this case, a class or module that defines a method is Blah.
So I think Blah.new.method(:x).owner should return Blah.

I don't catch your point.
Blah.new.x(1) calls MyMod#x, so Blah.new.method(:x).owner should return MyMod, shouldn't it?

#2 [ruby-dev:47977] Updated by Shugo Maeda over 2 years ago

  • Status changed from Open to Feedback

#3 [ruby-dev:47978] Updated by Anonymous over 2 years ago

Also for me, this is the expected behavior. MyMod is prepended before Blah, and therefore Blah.new.method( :x ) is taken from MyMod. As soon as you perform module MyMod; remove_method( :x ) end, method x will be again taken from Blah.

#4 [ruby-dev:47981] Updated by Kaneko Yuichiro over 2 years ago

Sorry, I misunderstood behavior of prepend. Shugo and Boris are right. Thanks for your quick responce. Please close this ticket :)

#5 [ruby-dev:47987] Updated by Shugo Maeda over 2 years ago

  • Status changed from Feedback to Rejected

Kaneko Yuichiro wrote:

Sorry, I misunderstood behavior of prepend. Shugo and Boris are right. Thanks for your quick responce. Please close this ticket :)

Thanks for your confirmation.

Also available in: Atom PDF