From: "Eregon (Benoit Daloze)" <noreply@ruby-lang.org>
To: ruby-core@neon.ruby-lang.org
Subject: [ruby-core:110208] [Ruby master Feature#18798] `UnboundMethod#==` with inherited classes
Date: Thu, 06 Oct 2022 12:07:30 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-99490.20221006120729.17@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18798.20220524015549.17@ruby-lang.org
Issue #18798 has been updated by Eregon (Benoit Daloze).
In code terms:
```ruby
module M
def foo
end
end
class A
prepend M
def foo
end
end
class B
prepend M
def foo
end
end
a = A.instance_method(:foo)
b = B.instance_method(:foo)
p a
p b
p a == b
p [a.super_method, b.super_method]
```
Currently:
```
#<UnboundMethod: A(M)#foo() umethod_iclass.rb:2>
#<UnboundMethod: B(M)#foo() umethod_iclass.rb:2>
false
[#<UnboundMethod: A#foo() umethod_iclass.rb:8>, #<UnboundMethod: B#foo() umethod_iclass.rb:14>]
```
Proposed (just changing UnboundMethod#==):
```
#<UnboundMethod: A(M)#foo() umethod_iclass.rb:2>
#<UnboundMethod: B(M)#foo() umethod_iclass.rb:2>
true
[#<UnboundMethod: A#foo() umethod_iclass.rb:8>, #<UnboundMethod: B#foo() umethod_iclass.rb:14>]
```
No class field anymore:
```
#<UnboundMethod: M#foo() umethod_iclass.rb:2>
#<UnboundMethod: M#foo() umethod_iclass.rb:2> (no visual difference)
true
[#<UnboundMethod: A#foo() umethod_iclass.rb:8>, #<UnboundMethod: B#foo() umethod_iclass.rb:14>]
```
----------------------------------------
Feature #18798: `UnboundMethod#==` with inherited classes
https://bugs.ruby-lang.org/issues/18798#change-99490
* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Now `UnboundMethod` for a same method from a superclass and an inherited class are not `==`.
```ruby
class C
def foo = :C
$mc = instance_method(:foo)
end
class D < C
$md = instance_method(:foo)
end
p $mc == $md #=> false
p $mc.owner #=> C
p $mc.owner == $md.owner #=> true
p $mc.source_location == $md.source_location #=> true
p $mc.inspect #=> "#<UnboundMethod: C#foo() t.rb:3>"
p $md.inspect #=> "#<UnboundMethod: D(C)#foo() t.rb:3>"
```
How about to make it `UnboundMethod#==` return true for this case?
Rule: "return true if the UnboundMethod objects point to a same method definition" seems simple.
FYI: On aliased unbound methods point to a same method are `==`.
```ruby
class C
def foo = :C
alias bar foo
$mfoo = instance_method(:foo)
$mbar = instance_method(:bar)
end
p $mfoo, $mbar
#=> #<UnboundMethod: C#foo() t.rb:2>
#=> #<UnboundMethod: C#bar(foo)() t.rb:2>
p $mfoo == $mbar #=> true
```
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2022-10-06 12:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-24 1:55 [ruby-core:108659] [Ruby master Bug#18798] `UnboundMethod#==` with inherited classes ko1 (Koichi Sasada)
2022-05-24 6:40 ` [ruby-core:108662] " sawa (Tsuyoshi Sawada)
2022-05-24 19:18 ` [ruby-core:108674] " jeremyevans0 (Jeremy Evans)
2022-05-24 19:49 ` [ruby-core:108676] " Eregon (Benoit Daloze)
2022-05-24 19:50 ` [ruby-core:108677] " Eregon (Benoit Daloze)
2022-05-25 0:28 ` [ruby-core:108688] [Ruby master Feature#18798] " ko1 (Koichi Sasada)
2022-05-25 0:32 ` [ruby-core:108689] " ko1 (Koichi Sasada)
2022-08-20 19:48 ` [ruby-core:109602] " Eregon (Benoit Daloze)
2022-09-11 10:45 ` [ruby-core:109887] " joel@drapper.me (Joel Drapper)
2022-10-06 6:07 ` [ruby-core:110197] " matz (Yukihiro Matsumoto)
2022-10-06 12:00 ` [ruby-core:110207] " Eregon (Benoit Daloze)
2022-10-06 12:07 ` Eregon (Benoit Daloze) [this message]
2022-10-06 14:29 ` [ruby-core:110209] " mame (Yusuke Endoh)
2022-10-06 16:20 ` [ruby-core:110215] " Eregon (Benoit Daloze)
2022-12-01 5:48 ` [ruby-core:111106] " matz (Yukihiro Matsumoto)
2022-12-06 9:13 ` [ruby-core:111219] " ko1 (Koichi Sasada)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-99490.20221006120729.17@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
--cc=ruby-core@neon.ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).