From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,SPF_PASS,T_DKIM_INVALID shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id C5FD72047F for ; Tue, 26 Sep 2017 08:34:10 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 570AC120A11; Tue, 26 Sep 2017 17:34:09 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 669E7120A0F for ; Tue, 26 Sep 2017 17:34:07 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=OpbUIQ0x5I6cbIOl4tpC2UU5+00=; b=mjnUrE/oYeTXFBtNcR XToZkDyVYDJdGZvyF84hPF6Turb/hrG3WjsCGZSuOeNQZBdO13S5ncgVsm1E8h2U RBqvY66N26IqDGpTqSp2LkKq0opFQGud4xp8LB7tSTfDrzrXWD3xgmR50jInHzfj idIBv3W8pyVYpypjHAhTOhlFQ= Received: by filter0013p3mdw1.sendgrid.net with SMTP id filter0013p3mdw1-6830-59CA10FC-1B 2017-09-26 08:34:04.343645534 +0000 UTC Received: from herokuapp.com (ec2-54-196-207-17.compute-1.amazonaws.com [54.196.207.17]) by ismtpd0007p1iad2.sendgrid.net (SG) with ESMTP id My-o9NUCTC-Z3_I4MWZQ3Q Tue, 26 Sep 2017 08:34:04.217 +0000 (UTC) Date: Tue, 26 Sep 2017 08:34:04 +0000 (UTC) From: matz@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 58119 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 12533 X-Redmine-Issue-Author: chucke X-Redmine-Issue-Assignee: matz X-Redmine-Sender: matz 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-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5ErdpRNGQ7tVHfOELJjgAw6t58QFJreYSfmo dk6LidBt9KvpupQVXtcDKvFaNC3Kw4T06zczLS3CszPYgmugYbWqP9ryMYnUKHh39kaC8sfpYvPtbe u2ZZNvMoLW4eqCrrQSdYj/ZwJ7AeyHbMok2kDItXEiXQuxc7O9s6+SY7dw== X-ML-Name: ruby-core X-Mail-Count: 83019 Subject: [ruby-core:83019] [Ruby trunk Feature#12533] Refinements: allow modules inclusion, in which the module can call internal methods which it defines. X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #12533 has been updated by matz (Yukihiro Matsumoto). As you may know, `include` inserts the module in the inheritance hierarchy. In this case, `module Extensions` is inserted above `String` in the `using Refinary` scope. That means the lexical scope of `vegetables` and `potatoes` are different from the refined scope so that `potatoes` cannot be called from `vegetables` because the scope is not refined. The situation is a bit complex. Do you follow me? In some other class extension proposals found in other languages (for example, ClassBox in Java), scopes of methods called from within ClassBox are also modified. This is called local rebinding. But we don't choose that because it has bigger side effects. We chose the safer side. The issue is by `include` we might expect the features from the included module are available but in fact, they aren't due to the mechanism of `include` and refinements. So I counter-propose a new feature, `Module#inject`. Unlike `include`, `inject` does not modify inheritance hierarchy. Instead, it copies attributes (constants, modules, and refinements) into the target class/module. shevegen, We have no concrete plan to refine the refinement. We are vaguely thinking about combining `require` and `using` in some way. Just idea. Matz. ---------------------------------------- Feature #12533: Refinements: allow modules inclusion, in which the module can call internal methods which it defines. https://bugs.ruby-lang.org/issues/12533#change-66931 * Author: chucke (Tiago Cardoso) * Status: Assigned * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- Right now this isn't possible: ~~~ruby module Extensions def vegetables ; potatoe ; end def potatoe ; "potatoe" ; end end module Refinary refine String do # this doesn't work include Extensions # this would work... # def vegetables ; potatoe ; end # def potatoe ; "potatoe" ; end end end using Refinary puts "tomatoe".vegetables #=> in
': undefined method 'vegetables' for "tomatoe":String ~~~ Wrongly reported as a bug [here](https://bugs.ruby-lang.org/issues/12514). According to Shugo Maeda, this was expected behaviour. I argued that this is the way most monkey-patches work, and if Refinements can't cover the use case of inserting a custom DSL which references itself in the classes it refines, it can't fully replace monkey-patches, which I read was the main reason Refinements have been added to the language. -- https://bugs.ruby-lang.org/