如何检测 Ruby 中哪些模块依赖于哪些模块?
哪些工具可以确定哪些模块具有从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我不知道 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.