Skip to content

Instantly share code, notes, and snippets.

@jacobsimeon
Created December 29, 2011 01:58
Show Gist options
  • Save jacobsimeon/1531123 to your computer and use it in GitHub Desktop.
Save jacobsimeon/1531123 to your computer and use it in GitHub Desktop.
Count the number of lines in the specified pattern
root_dir = ARGV[0] || "."
ext = ARGV[1] || "rb"
pattern = "#{root_dir}/**/*.#{ext}"
puts "Counting lines in files which match: #{pattern}"
count = 0
Dir[pattern].each do |file|
lines_in_file = 0
if File.exists? file
contents = File.read(file).split("\n")
contents.each{ |line| count +=1 and lines_in_file +=1 unless line =~ /^\s*($|#)/ }
end
puts "#{file} : #{lines_in_file} lines"
end
puts "#{count} lines of real code"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment