问题描述
我有一个包含很多类/模块的 Ruby 应用程序,其中一些没有使用.有没有一种简单的方法可以找出哪个?
I have a Ruby app with a lot of classes/modules, and some of them are not used. Is there an easy way of finding out which?
我正在考虑做一个配置文件,然后使用它的输出.还有其他想法吗?
I was thinking to do a profile, and then work with it's output. Any other ideas?
推荐答案
像 rcov 这样的覆盖工具可能会有所帮助.
A coverage tool, like rcov might help.
https://github.com/relevance/rcov
当您发现测试未涵盖的方法时,您应该为它们编写测试或找出它们是否被使用.
As you find methods that are not covered by tests, you should write tests for them or find out if they are used at all.
删除未使用的方法是重构的一部分,如果您有太多的类可能是代码异味,也需要重构.
Removing unused methods is part of refactoring, if you have too many classes that can be a code smell that needs refactored also.
这篇关于如何在 Ruby 应用程序中找到未使用的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!