Skip to content

Instantly share code, notes, and snippets.

@omegahm
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omegahm/2b92bb0fa1e92ef07017 to your computer and use it in GitHub Desktop.
Save omegahm/2b92bb0fa1e92ef07017 to your computer and use it in GitHub Desktop.
Find unused Ruby methods in current project
skip_methods = %w(new create edit update destroy index show initialize to_s call as_json page per_page build up down change)
output = `grep -hir "^\s*def\s" *`
methods = output.split("\n")
puts "Found #{methods.size} methods."
ununsed_methods = []
methods.each_with_index do |line, i|
line = line.gsub(/^\s*/, '')
.gsub(/\(.*/, '')
.gsub(/def /, '')
.gsub(/self\./, '')
next if skip_methods.include?(line)
next if line[-1] == '='
puts "(#{i}) Looking for #{line}."
if `grep -hir "#{line}" *`.split("\n").size == 1
puts "\tFound unused: #{line}"
ununsed_methods << line
end
end
puts "UNUSED METHODS:\n"
p ununsed_methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment