by Brian Landau of Viget Labs <brian.landau@viget.com>
- GitHub Project
- RubyForge Project
- RDoc
Doppelganger helps you to find areas of your code that are good places to refactor.
It does this by finding methods and blocks that are duplicates or have less then a set threshold level of difference or be less then a specified percent different. This library can either be used with in another larger code metric/heuristic library, or called from the command line.
-
Find duplicate methods and blocks.
-
Find methods and blocks similar by a threshold level of difference.
-
Find methods and blocks similar by threshold percentage.
-
Uses the Diff::LCS library for finding differences.
-
Uses RubyParser to compare methods.
-
Outputs the set of similar/duplicate nodes together and what files they are in and their line numbers.
Doing the Diff::LCS on all the flattened Sexps is a very time consuming and processor intense operation. This means doing the “diff” or “percent_diff” comparisons on large libraries can take a very long time.
-
ruby_parser
-
sexp_processor
-
Diff::LCS
-
Ruby2Ruby
-
HighLine
-
Facets
Find duplicates and methods have 5 or less differences.
$ doppelganger -n 5 project_dir/lib
Find duplicates and methods that are 10 percent different or less.
$ doppelganger -p 10 project_dir/lib
sudo gem install doppelganger
Inspired and based off of Giles Bowkett’s Towelie.
Parts also influenced or extracted by Ryan Davis’ Flay.