ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: shyouhei@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:80756] [Ruby trunk Bug#13249][Assigned] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
Date: Tue, 18 Apr 2017 04:38:45 +0000	[thread overview]
Message-ID: <redmine.journal-64312.20170418043845.dd25da3a31a7c290@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13249.20170224191346@ruby-lang.org

Issue #13249 has been updated by shyouhei (Shyouhei Urabe).

Status changed from Open to Assigned
Assignee set to ko1 (Koichi Sasada)

We looked at this issue in yesterday's developer meeting.

The use of private in evolve75/RubyTree shown in the description is in fact wrong (methods are defined in a wrong place).  That example made us think that the use of private in a method is a code smell.

We would forbid such usage in a future.  For the time being, let us show warning message.

----------------------------------------
Bug #13249: Access modifiers don't have an effect inside class methods in Ruby >= 2.3
https://bugs.ruby-lang.org/issues/13249#change-64312

* Author: abotalov (Andrei Botalov)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* 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
~~~




-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2017-04-18  3:59 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 ` [ruby-core:79774] " shevegen
2017-02-26 11:41 ` [ruby-core:79787] " botalov.andrey
2017-04-18  4:38 ` shyouhei [this message]
2017-05-19  7:34 ` [ruby-core:81261] " 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-64312.20170418043845.dd25da3a31a7c290@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).