Skip to content

Instantly share code, notes, and snippets.

@jacobat
Created July 20, 2009 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jacobat/150879 to your computer and use it in GitHub Desktop.
Save jacobat/150879 to your computer and use it in GitHub Desktop.
Quick'n'dirty script for figuring out which methods are unused in a Rails project
#!/usr/bin/env ruby
grep_result = `grep -ri "def " #{ARGV.join(' ')}`
methods = grep_result.split("\n").collect do |line|
md = line.match(/.*:\s+def ([a-z_]+)(\((.*)\))?/i)
md.to_a[1]
end
filtered_methods = methods.uniq - ["initialize"]
dirs = (Dir.glob("*") - ['vendor', 'log']).join(" ")
filtered_methods.each do |method_name|
cmd = "grep -ri #{method_name} #{dirs}"
lines = `#{cmd}`
puts "#{method_name} only found once" if lines.split("\n").size < 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment