ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: botalov.andrey@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:79770] [Ruby trunk Bug#13249] Access modifiers don't have an effect inside class methods in Ruby >= 2.3
Date: Sat, 25 Feb 2017 07:11:18 +0000	[thread overview]
Message-ID: <redmine.journal-63196.20170225071118.9d72c0a5b2f26233@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13249.20170224191346@ruby-lang.org

Issue #13249 has been updated by Andrei Botalov.


Well, ability to declare `private` methods inside class methods seems strange given that it's not possible to declare private methods inside instance methods:

~~~ ruby
class C
  def foo
    private def bar
    end
  end
end
C.new.foo # NoMethodError is raised
~~~

So I'm not sure which route would be better.

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

* 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/

  parent reply	other threads:[~2017-02-25  6:41 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 ` botalov.andrey [this message]
2017-02-25 19:18 ` [ruby-core:79774] " shevegen
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-63196.20170225071118.9d72c0a5b2f26233@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).