From: "jeremyevans0 (Jeremy Evans)" Date: 2022-06-14T20:10:46+00:00 Subject: [ruby-core:108917] [Ruby master Bug#18826] Symbol#to_proc inconsistent, sometimes calls private methods Issue #18826 has been updated by jeremyevans0 (Jeremy Evans). I agree with the @Eregon 's analysis, and submitted a pull request that makes Symbol#to_proc return a proc that will only call public methods: https://github.com/ruby/ruby/pull/6018 . I'm not happy with the implementation as it copies and modifies the code for `vm_call_method`, but I don't know a better way to fix it. This does cause a failure in rubyspec (which the pull request fixes), but I think that's due to the spec implementation (def at top-level defines private methods), and not by design. I'm guessing this will cause backwards compatibility issues, though hopefully they will be small, as found by TruffleRuby. I don't think it would be a good idea to backport the fix. ---------------------------------------- Bug #18826: Symbol#to_proc inconsistent, sometimes calls private methods https://bugs.ruby-lang.org/issues/18826#change-98002 * Author: bjfish (Brandon Fish) * Status: Open * Priority: Normal * ruby -v: 3.0.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- The following usage calls a protected method and prints "hello": ``` ruby class Test protected def referenced_columns puts "hello" end end Test.new.tap(&:referenced_columns) ``` However, the following usage results in a NoMethodError: ``` ruby class Integer private def foo 42 end end (1..4).collect(&:foo) ``` It seems to be a bug that tap calls a private method. It is also inconsistent with collect not calling private methods. -- https://bugs.ruby-lang.org/ Unsubscribe: