def stat(path) Dir.foreach(path) do |file| if file != "." && file != ".." then filePath = path + "/" + file if File.directory? filePath then stat(filePath); elsif file =~ /(\.java|\.js|\.jsp)$/ then @code_lines += file_code_line(filePath); end end end end
private def file_code_line(filePath) lines = 0 File.open(filePath,"r") do |file| in_comment = false; file.each_line do |line| line.strip! if line.index("/*") then in_comment = true elsif line.index("*/") then in_comment = false elsif !line.empty? && !in_comment && !line.index("//") then lines += 1 end end end puts "#{filePath} : #{lines}" lines end end