Project

General

Profile

Bug #7613

An Alias for a class method inherited from the Class class is not equal to the original method

Added by zhangsu (Su Zhang) almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p327 (2012-11-10) [i386-mingw32]
Backport:
[ruby-core:51105]

Description

class Stream
  class << self
    alias_method :open, :new
  end
end

open = Stream.method(:open)
new = Stream.method(:new)
p open, new                   # => #<Method: Stream.new>, #<Method: Class#new>
p open.receiver, new.receiver # => Stream, Stream
p open == new                 # => false

Expect the last line to return true, but got false. According to the documentation for Method#==:

Two method objects are equal if they are bound to the same object and refer to the same method definition.

Here, open and new are all bound to Stream and I expect them to refer to the method definition too.

Associated revisions

Revision d5a39c0a
Added by shugo (Shugo Maeda) almost 7 years ago

  • proc.c (method_eq): fix the documentation to refer to owner.
    [ruby-core:51105] [Bug #7613]

  • test/ruby/test_method.rb (test_alias_onwer): new test to confirm
    that `a == b' returns false if owners of a and b are different.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 38638
Added by shugo (Shugo Maeda) almost 7 years ago

  • proc.c (method_eq): fix the documentation to refer to owner.
    [ruby-core:51105] [Bug #7613]

  • test/ruby/test_method.rb (test_alias_onwer): new test to confirm
    that `a == b' returns false if owners of a and b are different.

Revision 38638
Added by shugo (Shugo Maeda) almost 7 years ago

  • proc.c (method_eq): fix the documentation to refer to owner.
    [ruby-core:51105] [Bug #7613]

  • test/ruby/test_method.rb (test_alias_onwer): new test to confirm
    that `a == b' returns false if owners of a and b are different.

Revision 38638
Added by shugo (Shugo Maeda) almost 7 years ago

  • proc.c (method_eq): fix the documentation to refer to owner.
    [ruby-core:51105] [Bug #7613]

  • test/ruby/test_method.rb (test_alias_onwer): new test to confirm
    that `a == b' returns false if owners of a and b are different.

History

#1

Updated by shugo (Shugo Maeda) almost 7 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r38638.
Su, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • proc.c (method_eq): fix the documentation to refer to owner.
    [ruby-core:51105] [Bug #7613]

  • test/ruby/test_method.rb (test_alias_onwer): new test to confirm
    that `a == b' returns false if owners of a and b are different.

Updated by shugo (Shugo Maeda) almost 7 years ago

zhangsu (Su Zhang) wrote:

class Stream
  class << self
    alias_method :open, :new
  end
end

open = Stream.method(:open)
new = Stream.method(:new)
p open, new                   # => #<Method: Stream.new>, #<Method: Class#new>
p open.receiver, new.receiver # => Stream, Stream
p open == new                 # => false

Expect the last line to return true, but got false. According to the documentation for Method#==:

open == new returns false because their owners are different.

p [open.owner, new.owner] #=> [#<Class:Stream>, Class]

Two method objects are equal if they are bound to the same object and refer to the same method definition.

Here, open and new are all bound to Stream and I expect them to refer to the method definition too.

I've fixed the documentation of Method#== as follows:

Two method objects are equal if they are bound to the same
object and refer to the same method definition and their owners are the
same class or module.

Updated by shugo (Shugo Maeda) almost 7 years ago

shugo (Shugo Maeda) wrote:

open == new returns false because their owners are different.

p [open.owner, new.owner] #=> [#<Class:Stream>, Class]

I forgot to explain why Method#== returns false if owners are different.
If owners of methods are different, the behavior of super is different in the methods,
so Method#== should not return true for the methods.

Also available in: Atom PDF