如何检测 Ruby 中哪些模块依赖于哪些模块?

发布于 2024-11-17 21:27:56 字数 842 浏览 2 评论 0原文

哪些工具可以确定哪些模块具有从 Ruby 中的其他模块调用方法的方法?

背景:我正在将 808 线路模块分解为更小的模块,并创建了 12 个子模块。然而,其中一个模块中的某些方法正在调用另一个子模块中的方法。这可能没问题,也可能没问题,具体取决于被调用方法的模块是否是通用功能。

module DisplayStatistics1
  def display_statistics_1_foo
    calculate_statistics_foo # call a method that's in CalculateStatistics - this is ok
    display_statistics_2_bar # call a method that's in DisplayStatistics2 - this is bad
  end

  # other methods omitted
end

# modules DisplayStatistics2 and CalculateStatistics omitted

class ExampleClass
  include DisplayStatistics1
  include DisplayStatistics2
  include CalculateStatistics
end

理想情况下,分析工具将显示 DisplayStatistics1 依赖于 DisplayStatistics2 以及 CalculateStatistics

更新:也许我不应该这样做 - 也许我应该将它们分成类。这样,我就能确切地知道什么取决于什么!

What tools can determine which modules have methods that are calling methods from other modules in Ruby?

Background: I'm partway through breaking a 808 line module into smaller modules, having created 12-submodules. However, some of the methods in one of the modules are calling methods in another sub-module. This may or may not be ok, depending on whether the module of the called method is meant to be common functionality.

module DisplayStatistics1
  def display_statistics_1_foo
    calculate_statistics_foo # call a method that's in CalculateStatistics - this is ok
    display_statistics_2_bar # call a method that's in DisplayStatistics2 - this is bad
  end

  # other methods omitted
end

# modules DisplayStatistics2 and CalculateStatistics omitted

class ExampleClass
  include DisplayStatistics1
  include DisplayStatistics2
  include CalculateStatistics
end

Ideally the analysis tool would show that DisplayStatistics1 has dependencies on DisplayStatistics2 as well as on CalculateStatistics.

Update: Maybe I shouldn't have done it this way - maybe I should have split them up into classes instead. That way, I'd have known for sure what depended on what!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岛徒 2024-11-24 21:27:56

虽然我不知道 Ruby 是否有静态分析工具,但最接近您想要的工具是 rubyprof< /a>.这可以生成多种格式的调用图,包括 HTML 树,甚至 GraphViz 箱线图。

While I'm not aware of a static analysis tool for Ruby, the one that seems closest to what you want is rubyprof. This can generate a callgraph in many formats, including an HTML tree and even a GraphViz box-and-line plot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文