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=-2.9 required=3.0 tests=AWL,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 162601F453 for ; Fri, 15 Feb 2019 16:42:44 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2C548121D8A; Sat, 16 Feb 2019 01:42:40 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 58A8A1217EE for ; Sat, 16 Feb 2019 01:42:38 +0900 (JST) Received: by filter0086p3las1.sendgrid.net with SMTP id filter0086p3las1-545-5C66EBFA-13 2019-02-15 16:42:34.2223057 +0000 UTC m=+53427.896077969 Received: from herokuapp.com (ec2-54-221-130-143.compute-1.amazonaws.com [54.221.130.143]) by ismtpd0004p1iad2.sendgrid.net (SG) with ESMTP id _XBRCUYlRF-imLgdzpsZaA for ; Fri, 15 Feb 2019 16:42:34.057 +0000 (UTC) Date: Fri, 15 Feb 2019 16:42:35 +0000 (UTC) From: eregontp@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 67022 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15608 X-Redmine-Issue-Author: Eregon X-Redmine-Sender: Eregon 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS49s4V6HjVCHU0Sl6qOeIEvVV9PWRvVQQWE6B YLI0tDwV4J3YDWdFl4764pEgc1AKEIbsqIP/I2GxH1ifDSZelLfo+TgaPdec6ZefhphKwf4UOwKkz5 2H52/7Jz1tj38KTExDkWmM9ZRmGK1pvaHfVjXuEukPOpVja1XwWAF6wcMA== X-ML-Name: ruby-core X-Mail-Count: 91570 Subject: [ruby-core:91570] [Ruby trunk Bug#15608] What should be the correct output for Method#inspect with singleton methods? 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 #15608 has been reported by Eregon (Benoit Daloze). ---------------------------------------- Bug #15608: What should be the correct output for Method#inspect with singleton methods? https://bugs.ruby-lang.org/issues/15608 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- bug.rb: ```ruby class C def foo end end obj = C.new class << obj alias bar foo end p obj.method(:foo).owner p obj.method(:foo) raise unless obj.method(:foo).owner == C p obj.method(:bar).owner p obj.method(:bar) raise unless obj.method(:bar).owner == obj.singleton_class ``` ``` $ chruby 2.0.0 $ ruby -v bug.rb ruby 2.0.0p648 (2015-12-16) [x86_64-linux] C # #> # $ chruby 2.3.8 $ ruby -v bug.rb ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux] C # #> #.bar(foo)> $ chruby 2.4.5 $ ruby -v bug.rb ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux] C #.foo> #> #.bar(foo)> Same for 2.5.3 and 2.6.1 ``` I think Method#inspect should show on which Module the method is defined, and only singleton methods should be shown as `receiver.method`, so: ``` C # #> #.bar(foo)> ``` Which only Ruby 2.3 does interestingly. --- What's the meaning of the `C1(C2)` notation? It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}(#{owner})` depending on the version: ```ruby class D < C end d = D.new p d.method(:foo) d.singleton_class p d.method(:foo) ``` ``` 2.0-2.3: # # 2.4-2.6: # #.foo> ``` I think the Ruby 2.4+ it's confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method. Do you agree what I describe should be the correct behavior? Can we fix it then? -- https://bugs.ruby-lang.org/