检测类方法中的新方法可见性

20 ruby

这是一个代码示例:

class Foo
  def self.create_method
    def example_method
      "foo"
    end
  end

  private

  create_method
end

Foo.public_instance_methods(false) # => [:example_method]
Run Code Online (Sandbox Code Playgroud)

是否有可能检测到create_method从类Foo私有区域调用的类方法?

在上面的示例中,该信息可用于example_method公开或私有,具体取决于create_method调用的位置.

Avd*_*ept 0

尝试https://github.com/ruby-prof/ruby-prof

有一个特点:

调用树配置文件 - 以适合 KCacheGrind 分析工具的调用树格式输出结果。

这可能对你有帮助