Ruby 请问一下 ruby 现在可以显示调用私有方法了(self.private_method)?

HyeKyoZ-github · February 25, 2024 · Last by HyeKyoZ-github replied at February 26, 2024 · 343 hits


class C
  def public_method
    self.private_method
  end

  private
  def private_method; end

end

C.new.public_method

上面代码在 ruby 3.3.0 里面成功执行,没报错。执行结果如图

搜了一下,是 2.7 版时改的

Reply to zhuoerri

昨天和同事讨论这个问题才发现改了,谢谢😀

HyeKyoZ-github closed this topic. 29 Feb 19:54
You need to Sign in before reply, if you don't have an account, please Sign up first.