Skip to content

Commit a0ff270

Browse files
committed
Merge pull request rails#4753 from rahul100885/rahul100885_work
Used block to make sure file get auto closed after use
2 parents 30327a0 + 6831ab1 commit a0ff270

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

railties/lib/rails/code_statistics.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,26 @@ def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
3737

3838
next unless file_name =~ pattern
3939

40-
f = File.open(directory + "/" + file_name)
4140
comment_started = false
42-
while line = f.gets
43-
stats["lines"] += 1
44-
if(comment_started)
45-
if line =~ /^=end/
46-
comment_started = false
47-
end
48-
next
49-
else
50-
if line =~ /^=begin/
51-
comment_started = true
41+
42+
File.open(directory + "/" + file_name) do |f|
43+
while line = f.gets
44+
stats["lines"] += 1
45+
if(comment_started)
46+
if line =~ /^=end/
47+
comment_started = false
48+
end
5249
next
50+
else
51+
if line =~ /^=begin/
52+
comment_started = true
53+
next
54+
end
5355
end
56+
stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
57+
stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
58+
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
5459
end
55-
stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
56-
stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
57-
stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
5860
end
5961
end
6062

0 commit comments

Comments
 (0)