看代码

# encoding: utf-8
class CodeLineStat
attr_reader :code_lines def initialize
@code_lines = 0
end def stat(path)
Dir.foreach(path) do |file|
if file != "." && file != ".." then
filePath = path + "/" + file
if File.directory? filePath then
stat(filePath);
elsif file =~ /(\.cs|\.aspx)$/ then
@code_lines += file_code_line(filePath);
end
end
end
end private
def file_code_line(filePath)
lines = 0
File.open(filePath,"r:utf-8") 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 cl = CodeLineStat.new
cl.stat(ARGV[0])
title = "總共有代碼行:".encode('big5')
puts cl.code_lines

最新文章

  1. 微信公共平台开发-(.net实现)3--发送文本消息
  2. python学习笔记-(十)面向对象基础
  3. zxing 一维码部分深入分析与实际应用,识别卡片数量,Android数卡器
  4. SQLServer 常用日期处理
  5. AJAX制作JSON格式的实时更新数据的方法
  6. 以Outlook样式分组和排列数据项
  7. 支付宝wap支付调起客户端
  8. ubuntu安装输入法
  9. Hibernate学习(三)———— 一对多映射关系
  10. MongoDB T-shirt 来了
  11. android studio 添加get,set方法快捷方式
  12. python中函数基础
  13. MyBatis SqlSessionDaoSupport实例
  14. [django]JsonResponse序列化数据
  15. 用 Django 做了一个照片分享网站
  16. Sqlserver 备份
  17. 数据库实例: STOREBOOK > 用户
  18. js输出大段html文档简便方法
  19. Javascript 535种方式!!!实现页面重载
  20. 【我的Android进阶之旅】快速创建和根据不同的版本类型(Dev、Beta、Release)发布Android 开发库到Maven私服

热门文章

  1. 并发编程(二):分析Boost对 互斥量和条件变量的封装及实现生产者消费者问题
  2. Spring注入
  3. 使用go reflect实现一套简易的rpc框架
  4. Android进阶(十四)Android Adapter详解
  5. android官方技术文档翻译——Case 标签中的常量字段
  6. ubuntu 开发环境配置及安装 nodejs
  7. Java应用程序使用系统托盘资源
  8. Ionic APP-Web SPA开发进阶(二)Ionic进阶之路由去哪了
  9. SpriteBuilder中不能编辑自定义类或不能给节点添加属性的解决
  10. 2015年北京的第一场雪-关于android学习的思考(84)