ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "jonathanhefner (Jonathan Hefner)" <noreply@ruby-lang.org>
To: ruby-core@neon.ruby-lang.org
Subject: [ruby-core:110483] [Ruby master Bug#19079] Modules included in a DelegateClass cannot override delegate methods
Date: Sun, 23 Oct 2022 03:01:06 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-19079.20221023030106.24242@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19079.20221023030106.24242@ruby-lang.org

Issue #19079 has been reported by jonathanhefner (Jonathan Hefner).

----------------------------------------
Bug #19079: Modules included in a DelegateClass cannot override delegate methods
https://bugs.ruby-lang.org/issues/19079

* Author: jonathanhefner (Jonathan Hefner)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.2p20
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Because `DelegateClass` defines delegate methods on the class itself, those delegate methods come first in the method lookup chain.  This prevents included modules from overriding delegate methods:

  ```ruby
  Base = Class.new do
    def foo
      "base"
    end
  end

  Helper = Module.new do
    def foo
      "helper"
    end
  end

  WithHelper = DelegateClass(Base) { include Helper }

  WithHelper.new(Base.new).foo
  # => "base"
  ```

One possible solution would be to define the delegate methods in a separate module.  That way, other modules could come before it in the method lookup chain.



-- 
https://bugs.ruby-lang.org/

       reply	other threads:[~2022-10-23  3:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-23  3:01 jonathanhefner (Jonathan Hefner) [this message]
2022-10-23  3:02 ` [ruby-core:110484] [Ruby master Bug#19079] Modules included in a DelegateClass cannot override delegate methods jonathanhefner (Jonathan Hefner)
2022-12-01  5:11 ` [ruby-core:111104] " matz (Yukihiro Matsumoto)
2022-12-01 12:38 ` [ruby-core:111126] " matz (Yukihiro Matsumoto)
2022-12-01 14:57 ` [ruby-core:111129] " Hanmac (Hans Mackowiak)
2022-12-01 17:19 ` [ruby-core:111132] " jonathanhefner (Jonathan Hefner)

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.issue-19079.20221023030106.24242@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).