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: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.1 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 21D9E1F453 for ; Thu, 7 Feb 2019 04:13:54 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 374AF121066; Thu, 7 Feb 2019 13:13:50 +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 26ABB121063 for ; Thu, 7 Feb 2019 13:13:47 +0900 (JST) Received: by filter0076p3iad2.sendgrid.net with SMTP id filter0076p3iad2-25451-5C5BB077-B 2019-02-07 04:13:43.185244397 +0000 UTC m=+118862.492456784 Received: from herokuapp.com (ec2-54-80-77-200.compute-1.amazonaws.com [54.80.77.200]) by ismtpd0039p1iad2.sendgrid.net (SG) with ESMTP id HOo48mAxSJOH6416MaY3Mg for ; Thu, 07 Feb 2019 04:13:43.179 +0000 (UTC) Date: Thu, 07 Feb 2019 04:13:44 +0000 (UTC) From: manga.osyo@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66900 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15374 X-Redmine-Issue-Author: osyo X-Redmine-Sender: osyo 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7FCfUIgsfdnb1dtINp/6zmBiX/XClfFJ4vgP RV0IKER0V6WZ0SaUIDLVOxL44cphrUXAxcpaTs3zsAtN3yL13ZoQY4U6pv78n4cY6vXhruwbSiWZgI 2D5VCX7UJz++rNqJcC3KuWHPVwpgClJ0qDv21tb/jW46otkgOnEDwxF6Zw== X-ML-Name: ruby-core X-Mail-Count: 91446 Subject: [ruby-core:91446] [Ruby trunk Feature#15374] Proposal: Enable refinements to `#method_missing` 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 #15374 has been updated by osyo (manga osyo). Yes, it will be the specification of Ruby. method_missing has a large side effect. So can use `using` to control by context. ```ruby module HashWithAsscessKeyToMethod refine Hash do # name is Symbol or String def method_missing(name) self[name] || self[name.to_s] end end end # Do not want to use Hash#method_missing hash = { name: "homu", age: 14 } pp hash[:name] # OK # pp hash.name # NG # Do want to use Hash#method_missing using HashWithAsscessKeyToMethod pp hash.name # OK ``` User can choose. ---------------------------------------- Feature #15374: Proposal: Enable refinements to `#method_missing` https://bugs.ruby-lang.org/issues/15374#change-76705 * Author: osyo (manga osyo) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Proposal enable refinements to `#method_missing`. It can be used in the following cases. ```ruby # Access key value with method using Module.new { refine Hash do # name is Symbol or String def method_missing(name) self[name.to_sym] || self[name.to_s] end end } hash = { name: "homu", "age" => 14 } pp hash.name # => "homu" pp hash.age # => "age" ``` `method_missing` is hard hacking. I would like to use Refinements with `method_missing`. pull request: https://github.com/ruby/ruby/pull/2036 -- https://bugs.ruby-lang.org/