Ruby script to check how many lines of code are in an application -


how write ruby script such get_lines.rb file_name.rb returns total number/lines of code in application recursive through folder > folder > foler such app/modes, app/controllers etc... files!

generally wouldn't - i'd use shell utility. seriously.

also, want include comments? etc. etc.

there's answer this, not using ruby here: how count lines of code in directory recursively?

if approaching intent of doing i'd this:

dir['**/*.*'].each |fname|   puts "#{fname} #{linecount(fname)}" end 

linecount

def linecount(fname)   file.open(fname, "r") |f|     return f.readlines.length   end end 

this nasty hack way, because reads whole file memory see how long array is, might want each line , count them read through.

you rid of blanks or lines comments incrementing counter.

something like

lines = f.readlines lines.delete_if { |l| l =~ /^[[:space:]]*#|^$/ } return lines.length 

i haven't tested regexp way.

as exercise reader - work out 'if' statement need put on end of puts stop barfing on directories :d


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -