From: shevegen@... Date: 2017-02-25T19:18:54+00:00 Subject: [ruby-core:79774] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3 Issue #13249 has been updated by Robert A. Heiler. The examples confuse me a bit. Does private actually make sense on any class-method / singleton method? I understand it as a limitation for methods on the class, where outside calls are not allowed, only internal ones (though ruby allows one to bypass these anyway via .send). I am also confused by the second example: class C def self.foo private def bar end end end C.foo C.new.bar Is that not equivalent to private def self.bar ? So why would this work on the C.new.bar() level? It is however had interesting that this worked on 2.2 and below but was changed past that point. ---------------------------------------- Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3 https://bugs.ruby-lang.org/issues/13249#change-63199 * Author: Andrei Botalov * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.3.0, 2.4.0 * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Simple example: ~~~ ruby class C def self.foo private def bar end end end C.foo C.new.bar ~~~ This code runs fine on Ruby 2.3 and Ruby 2.4. It raises NoMethodError on Ruby 2.2 and prior versions. I would expect an error to be raised. Here is some code that actually uses private access modifier inside a class method - https://github.com/evolve75/RubyTree/blob/db48c35b0a3b96e4da473b095cc00e454d8a9996/lib/tree/utils/camel_case_method_handler.rb#L60 By the way, this code raises an error as expected on Ruby 2.3 and Ruby 2.4: ~~~ ruby class C def self.foo private def bar end end end C.foo C.new.bar ~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: