ruby簡單的代碼行統計工具
2024-09-28 04:46:46
看代码
# 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
最新文章
- 微信公共平台开发-(.net实现)3--发送文本消息
- python学习笔记-(十)面向对象基础
- zxing 一维码部分深入分析与实际应用,识别卡片数量,Android数卡器
- SQLServer 常用日期处理
- AJAX制作JSON格式的实时更新数据的方法
- 以Outlook样式分组和排列数据项
- 支付宝wap支付调起客户端
- ubuntu安装输入法
- Hibernate学习(三)———— 一对多映射关系
- MongoDB T-shirt 来了
- android studio 添加get,set方法快捷方式
- python中函数基础
- MyBatis SqlSessionDaoSupport实例
- [django]JsonResponse序列化数据
- 用 Django 做了一个照片分享网站
- Sqlserver 备份
- 数据库实例: STOREBOOK >; 用户
- js输出大段html文档简便方法
- Javascript 535种方式!!!实现页面重载
- 【我的Android进阶之旅】快速创建和根据不同的版本类型(Dev、Beta、Release)发布Android 开发库到Maven私服
热门文章
- 并发编程(二):分析Boost对 互斥量和条件变量的封装及实现生产者消费者问题
- Spring注入
- 使用go reflect实现一套简易的rpc框架
- Android进阶(十四)Android Adapter详解
- android官方技术文档翻译——Case 标签中的常量字段
- ubuntu 开发环境配置及安装 nodejs
- Java应用程序使用系统托盘资源
- Ionic APP-Web SPA开发进阶(二)Ionic进阶之路由去哪了
- SpriteBuilder中不能编辑自定义类或不能给节点添加属性的解决
- 2015年北京的第一场雪-关于android学习的思考(84)