finding dead ruby code with debride
My recent web adventures led me to the debride
gem: debride
statically analyzes your ruby code, trying to find methods which are never referenced.
As ruby is a very dynamic language, you’ll get some amount of false positives, but I was successful in finding several unused methods on several of our years-old codebases at Talkdesk.
The output of running debride is a list of methods (and which class or module they belong to) that debride cannot find a reference to in the code.
My workflow to remove unused code is to run debride, and for each method:
- grep the codebase to confirm that the method is not called or referenced in any way (e.g. invoked using :send or registered with a framework)
- use the git pickaxe to discover when the method was introduced and its last user removed
During my quick experiment of about an hour I was able to delete about a hundred LoC—and I didn’t even get through the whole list!
debride
is another interesting tool I’ve just added to my toolkit, and I hope it fits yours too.