From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS24940 94.130.0.0/16 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 886D41F601 for ; Thu, 1 Dec 2022 17:19:54 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.b="uBD2OSfn"; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id A261C7E673; Thu, 1 Dec 2022 17:19:47 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=uBD2OSfn; dkim-atps=neutral Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 78EAE7E668 for ; Thu, 1 Dec 2022 17:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc; s=s1; bh=mp+6zkWGbk7/mnHO/RoQS7V7eLdz73jwzSB3P2eqAr0=; b=uBD2OSfnEMwwkDAQakPsl0aXvq+YVaTsr/R4+lVLYrTl6a/YBK4aAcAIfr6l56EglQPl XgNfTKEyCmRMvsroXAKEaJVHYhEQxXaEGL6mg3MKm4BVQVpzXzWw39YTn6YGdUT/mP024/ s/ZIsxzk6fzoF3w35y0gb/wVEIIwgBZeCqe3XCA4W+gx1nK5v+bmySkIxfXfhzZKJFWR7P H9GlG666q9rf6gN57aFmp5GyB+6ShNGSD5Ch8kaCeey0mIJ+xlfWAb763By7l2V/CHAz3p qZnVIIFjqyDOT5Rc9tdWxZlzV+Cd3A77gA47tBo2uKhQ5O1D/bb+qiTgJx9MDVVQ== Received: by filterdrecv-69c5db5cf4-v9vnn with SMTP id filterdrecv-69c5db5cf4-v9vnn-1-6388E22D-32 2022-12-01 17:19:41.927952633 +0000 UTC m=+1188695.256263543 Received: from herokuapp.com (unknown) by geopod-ismtpd-3-0 (SG) with ESMTP id K_Fi4AObTGeSRKlDDnOEbA for ; Thu, 01 Dec 2022 17:19:41.851 +0000 (UTC) Date: Thu, 01 Dec 2022 17:19:41 +0000 (UTC) From: "jonathanhefner (Jonathan Hefner)" Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 19079 X-Redmine-Issue-Author: jonathanhefner X-Redmine-Sender: jonathanhefner X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 87484 X-SG-EID: =?us-ascii?Q?znQBMHNoD9M9rYIsmU=2F7tPeX6YAn+g3BalgaCcxASCQkQEkfyqZr2ejlvsEKLw?= =?us-ascii?Q?+neakOoEOccpn9AG2d6U81wkMOXnVsafKDBORYP?= =?us-ascii?Q?ivpqCt1geQtqUq4vQ=2FjKz9nbvMlVqKaayu5QVB3?= =?us-ascii?Q?tdmerMXpUgxSkdtyRVicQzNQUu5hPrbwP56I+hd?= =?us-ascii?Q?hoZOI6G26iVNgBenPItDH8nNmCJV7L8lxsO9Gjo?= =?us-ascii?Q?=2FYNeNuN9IqPN+ZqWwtmmj0jdcunn24mZyhq95nE?= =?us-ascii?Q?eoH3lj+KxdGxVvJgZyeC3xSfFYDOgbgXaT1gdon?= =?us-ascii?Q?gqk=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: IQBTL4DG6XRW2I6TJAW4S6LYP3MPSO57 X-Message-ID-Hash: IQBTL4DG6XRW2I6TJAW4S6LYP3MPSO57 X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:111132] [Ruby master Bug#19079] Modules included in a DelegateClass cannot override delegate methods List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #19079 has been updated by jonathanhefner (Jonathan Hefner). This issue occurred for a private module in Rails: https://github.com/rails/rails/pull/46189#discussion_r991440668. Using `include` in a subclass works. Using `prepend` also works, and is the workaround I used for the Rails module. However, my proposed solution for this issue (https://github.com/ruby/delegate/pull/14) also solves #19079 with a performance improvement. I opened this issue and #19079 because the current behavior seemed surprising to me. In particular, I expected the `DelegateClass` block to behave just like a `Class.new` block. I feel like that is a reasonable assumption based on [the documentation](https://github.com/ruby/delegate/blob/2e1272cadbf86a02a0084d03e336368556f0259e/lib/delegate.rb#L365-L369). But, if my assumption is wrong, then I understand the decision. ---------------------------------------- Bug #19079: Modules included in a DelegateClass cannot override delegate methods https://bugs.ruby-lang.org/issues/19079#change-100411 * Author: jonathanhefner (Jonathan Hefner) * Status: Rejected * 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/