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.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,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 E7DA51F461 for ; Sat, 13 Jul 2019 01:35:46 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 3CEB7120A45; Sat, 13 Jul 2019 10:35:39 +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 E52BC120B50 for ; Sat, 13 Jul 2019 10:35:35 +0900 (JST) Received: by filter0089p3mdw1.sendgrid.net with SMTP id filter0089p3mdw1-16731-5D293569-16 2019-07-13 01:35:37.551105987 +0000 UTC m=+806749.396637625 Received: from herokuapp.com (unknown [34.238.242.141]) by ismtpd0036p1iad1.sendgrid.net (SG) with ESMTP id QDpf79zfS1mZwdNmCVSkXA for ; Sat, 13 Jul 2019 01:35:37.525 +0000 (UTC) Date: Sat, 13 Jul 2019 01:35:37 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 69230 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 8743 X-Redmine-Issue-Author: stestagg X-Redmine-Sender: jeremyevans0 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: =?us-ascii?Q?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BIl1qyzbNJ1g2yHL3JH3TK0qsmSWqEJWMc5738u?= =?us-ascii?Q?r=2FCVA2V0m3rYL+anrDwDkiWoo=2FMwgQIANUz89iE?= =?us-ascii?Q?SrU4Ah2bva2sFsSB8kpYJYB0pjm=2F6zYjrkhEZCC?= =?us-ascii?Q?t22zQesYKOQV69JPFe41gAvhs=2FgOgg=2FQvow=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 93734 Subject: [ruby-core:93734] [Ruby master Bug#8743] Inconsistent behaviour calling public_methods on class (Plus documentation slightly ambiguous) 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 #8743 has been updated by jeremyevans0 (Jeremy Evans). Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN) Status changed from Open to Closed The reason for this interesting behavior is because the documentation for include flag (2nd argument) for `public_methods` is not precise. It states: ``` If the all parameter is set to false, only those methods in the receiver will be listed. ``` However, the behavior is actually: ``` If the all parameter is set to false, the list will include methods in ancestors, stopping after a non-singleton class is encountered (including the methods from the non-singleton class). ``` The lookup process for `Empty.public_methods(false)` is something like this: * Empty.singleton_class # adds no methods * Object.singleton_class # adds no methods * BasicObject.singleton_class # adds no methods * Class # adds 3 methods `[:allocate, :superclass, :new]` * Module # does not get here, as Class is not a singleton class So that is the reason `Empty.public_methods(false)` gives you `[:allocate, :superclass, :new]`. `B.public_methods(false)` including singleton methods from `A` is similar: * B.singleton_class # adds no methods * A.singleton_class # adds 1 method `[:bar]` * Object.singleton_class # adds no methods * BasicObject.singleton_class # adds no methods * Class # adds 3 methods `[:allocate, :superclass, :new]` * Module # does not get here, as Class is not a singleton class Which is the reason that `Bar.public_methods(false)` gives you `[:bar, :allocate, :superclass, :new]`. I'm not sure it worth updating the documentation to be more precise in this area, but I'm open to suggestions. ---------------------------------------- Bug #8743: Inconsistent behaviour calling public_methods on class (Plus documentation slightly ambiguous) https://bugs.ruby-lang.org/issues/8743#change-79371 * Author: stestagg (Steve Stagg) * Status: Closed * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.1.0dev (2013-08-06 trunk 42401) [x86_64-darwin12.4.0] * Backport: ---------------------------------------- =begin = Background I was trying to identify classes on which a specific class method (def self.xx) was actually defined (in the case of multiple levels of inheritance). This currently doesn't seem to be possible, although the docs suggest that calling class.public_methods(false) should do this. While investigating, I discovered that the behaviour of calling instance.public_methods(false) is not consistent with that of calling class.public_methods(false) [They should be different, of course, but the behaviour should be consistent]. The attached test script highlights this. = Steps to Reproduce Run the attached ruby script = Expected Result Ideally, all tests pass, but at `least test_consistent_behaviour` should pass = Actual Results test_this_is_what_i_expect, and test_consistent_behaviour both fail. = Example test output steves@sapphire ~/s/t/ruby> env RUBYLIB=./lib ./ruby ~/foo.rb Run options: # Running tests: [2/5] PublicMethodsTest#test_consistent_behaviour = 0.00 s 1) Failure: PublicMethodsTest#test_consistent_behaviour [/Users/steves/foo.rb:73]: Differences: bar. "bar" is inherited from A, but doesn't include methods inherited from Object! [5/5] PublicMethodsTest#test_this_is_what_i_expect = 0.00 s 2) Failure: PublicMethodsTest#test_this_is_what_i_expect [/Users/steves/foo.rb:59]: Differences: allocate, new, superclass. Finished tests in 0.005998s, 833.6112 tests/s, 2834.2781 assertions/s. 5 tests, 17 assertions, 2 failures, 0 errors, 0 skips ruby -v: ruby 2.1.0dev (2013-08-06 trunk 42401) [x86_64-darwin12.4.0] Seen on ruby 1.8, 2.0 and trunk =end ---Files-------------------------------- foo.rb (2.22 KB) -- https://bugs.ruby-lang.org/