[ruby-core:95351] [Ruby master Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
From:
mame@...
Date:
2019-10-16 05:26:54 UTC
List:
ruby-core #95351
Issue #13249 has been updated by mame (Yusuke Endoh).
Assignee changed from ko1 (Koichi Sasada) to nobu (Nobuyoshi Nakada)
@nobu Could you review the patch?
----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-82059
* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* 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 # NoMethodError: private method `bar' called
~~~
---Files--------------------------------
warn-scope-visibility-in-method-13249.patch (4.18 KB)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>