From: shevegen@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:79774] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
Date: Sat, 25 Feb 2017 19:18:54 +0000 [thread overview]
Message-ID: <redmine.journal-63199.20170225191854.bd5ec9fb0b6baea8@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13249.20170224191346@ruby-lang.org
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/
next prev parent reply other threads:[~2017-02-25 18:48 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-13249.20170224191346@ruby-lang.org>
2017-02-24 19:13 ` [ruby-core:79751] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3 botalov.andrey
2017-02-24 19:34 ` [ruby-core:79752] " botalov.andrey
2017-02-24 19:35 ` [ruby-core:79753] " botalov.andrey
2017-02-24 23:20 ` [ruby-core:79758] " nobu
2017-02-25 7:11 ` [ruby-core:79770] " botalov.andrey
2017-02-25 19:18 ` shevegen [this message]
2017-02-26 11:41 ` [ruby-core:79787] " botalov.andrey
2017-04-18 4:38 ` [ruby-core:80756] [Ruby trunk Bug#13249][Assigned] " shyouhei
2017-05-19 7:34 ` [ruby-core:81261] [Ruby trunk Bug#13249] " ko1
2019-08-25 0:23 ` [ruby-core:94539] [Ruby master " merch-redmine
2019-10-16 5:26 ` [ruby-core:95351] " mame
2019-10-16 7:06 ` [ruby-core:95356] " nobu
2019-10-16 19:10 ` [ruby-core:95372] " merch-redmine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-63199.20170225191854.bd5ec9fb0b6baea8@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).