Skip to content

Instantly share code, notes, and snippets.

@louismullie
Created June 17, 2012 20:13
Show Gist options
  • Save louismullie/2945588 to your computer and use it in GitHub Desktop.
Save louismullie/2945588 to your computer and use it in GitHub Desktop.
Count the number of files, lines of code and comments in a Ruby project.
o = 0 # Number of files
n = 0 # Number of lines of code
m = 0 # Number of lines of comments
files = Dir.glob('/path/to/dir/**/*.rb')
files.each do |f|
next if FileTest.directory?(f)
o += 1
i = 0
lines = []
File.new(f).each_line do |line|
if line.strip[0] == '#'
m += 1
next
end
lines << line
i += 1
end
n += i
end
puts "#{o.to_s} files."
puts "#{n.to_s} lines of code."
puts "#{(n.to_f/o.to_f).round(2)} LOC/file."
puts "#{m.to_s} lines of comments."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment