# Unused methods

**URL:** <https://www.ruby-forum.com/t/unused-methods/69925>\
**Category:** Ruby\
**Created:** [September 25, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/unused-methods/69925 "2006-09-25T17:00:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![moneypenny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@moneypenny](https://www.ruby-forum.com/u/moneypenny)\
**Post date:** [September 25, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/unused-methods/69925/1 "2006-09-25T17:00:50Z")

</div>

I’m wondering if there is a good, quick way to determine unused methods  
in a large Ruby or Rails application. My situation is that I wrote a  
Rails app sometime last year, when I was first learning both Ruby and  
Rails, and coming back to it now, it looks like a PHP app that just  
happens to be written in Ruby (I came from PHP). So, I’m refactoring a  
lot of things to make it more modular and Ruby-esque, but I haven’t  
been deleting functionality along the way out of concern for keeping it  
working while I update it. Now, though, I would like to be able to  
have something parse my source and, for every method defined, have a  
count of how many times it is used, where it is called, etc. Is there  
a tool like this out there, or will I need to write such a beast?  
Thanks!

---

<div class="post-metadata">

**Author:** ![moneypenny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@moneypenny](https://www.ruby-forum.com/u/moneypenny)\
**Post date:** [September 25, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/unused-methods/69925/2 "2006-09-25T17:10:51Z")

</div>

Cheshire C. wrote:

> a tool like this out there, or will I need to write such a beast?  
> Grab Watir, and write acceptance tests for each feature in your project.

Now start whacking lines, and each time you do, pass all the tests. If a  
test fails unexpectedly, put the line back.

Another thing you brought from PHP is no unit tests, right?

Write them also, in the test folder.

---

<div class="post-metadata">

**Author:** ![moneypenny](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@moneypenny](https://www.ruby-forum.com/u/moneypenny)\
**Post date:** [September 25, 2006, 5:30pm UTC](https://www.ruby-forum.com/t/unused-methods/69925/3 "2006-09-25T17:30:57Z")

</div>

On 9/25/06, Cheshire C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> a tool like this out there, or will I need to write such a beast?  
> Thanks!

rcov (gem install rcov) will give you coverage info (i.e. what lines  
have been visited during a program run). Using it will of course  
require that you have tests that will walk all the possible paths.

You could use ParseTree[1] to build call graphs, but it would be much  
harder, so I say write the tests as well.

[1] [zenspider projects | software projects | by ryan davis](http://www.zenspider.com/ZSS/Products/ParseTree/index.html)
