Browse files

Used block to make sure file get auto closed after use

  • Loading branch information...
1 parent 30327a0 commit 6831ab11106c582a67bb5109921629059e690610 @rahul100885 rahul100885 committed Jan 30, 2012
Showing with 16 additions and 14 deletions.
  1. +16 −14 railties/lib/rails/code_statistics.rb
View
30 railties/lib/rails/code_statistics.rb
@@ -37,24 +37,26 @@ def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
next unless file_name =~ pattern
- f = File.open(directory + "/" + file_name)
comment_started = false
- while line = f.gets
- stats["lines"] += 1
- if(comment_started)
- if line =~ /^=end/
- comment_started = false
- end
- next
- else
- if line =~ /^=begin/
- comment_started = true
+
+ File.open(directory + "/" + file_name) do |f|
+ while line = f.gets
+ stats["lines"] += 1
+ if(comment_started)
+ if line =~ /^=end/
+ comment_started = false
+ end
next
+ else
+ if line =~ /^=begin/
+ comment_started = true
+ next
+ end
end
+ stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
+ stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
+ stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
end
- stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
- stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
- stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
end
end

0 comments on commit 6831ab1

Please sign in to comment.