[ruby-core:124587] [Ruby Bug#8743] Inconsistent behaviour calling public_methods on class (Plus documentation slightly ambiguous)
Issue #8743 has been updated by trinistr (Alexander Bulancov). I've been working on some tests using `public_methods`, and was bitten by this. I think a documentation update is definitely needed. Docs shouldn't straight-up lie. Though I personally think that Module (or Class?) should just have different implementations of these methods. Current behavior makes some sense for instances, but for classes it's plain weird. ---------------------------------------- Bug #8743: Inconsistent behaviour calling public_methods on class (Plus documentation slightly ambiguous) https://bugs.ruby-lang.org/issues/8743#change-116168 * Author: stestagg (Steve Stagg) * Status: Closed * ruby -v: ruby 2.1.0dev (2013-08-06 trunk 42401) [x86_64-darwin12.4.0] ---------------------------------------- =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/
participants (1)
-
trinistr (Alexander Bulancov)