• Overview

  • Download

  • Installation

  • Usage

  • Release Notes


CountLOC is a utility program, implemented in Ruby that provides support for generating LOC metrics for source code.

Initial releases will support counting lines of code in Ruby source code. Subsequent releases will add support for other programming languages such as Python, C, C++, C#, Java, Perl, etc. …


The latest release can be downloaded from:


CountLOC is packaged as a Ruby gem and as a .zip file.

.gem: % gem install countloc-x.y.z.gem

.zip: % unzip % cd countloc-x.y.z % ruby setup.rb install

.tgz: % tar zxf countloc-x.y.z.tgz % cd countloc-x.y.z % ruby setup.rb install


For full listing of options and usage: % countloc.rb –help To get the LOC metrics for a single Ruby file: % countloc.rb some_file.rb

To get the LOC metrics for multiple Ruby files: % countloc.rb some_file.rb some_other_file.rb

To get the LOC metrics for all Ruby files in the current directory: % countloc.rb *.rb or % countloc.rb .

To get the LOC metrics for all Ruby files in a directory tree with recursion into subdirectories: % countloc.rb -r . To export the results to a html file: % countloc.rb -r –html countloc.html .

To export the results to a csv file: % countloc.rb -r –csv countloc.csv .

Release Notes

Release 0.2.0:


  • Added support for exporting results in csv and html format.

  • Improved error handling - e.g. incorrect/missing command line options, file errors, etc.

  • Added setup.rb for ease of installation from the .zip/.tgz release formats.

  • Added CountLOC module to encapsulate methods and classes.


  • None

Release 0.1.0:


  • Added support for processing multiple files at once.

  • Added support for processing all .rb files in a directory.

  • Added support for recursing into directory trees.

  • Improved formatting of output.


  • #23380 - Not suppressing path information in the program name in the usage string.

  • #23379 - Incorrectly counting a # inside a single quoted string as a comment.

Release 0.0.1:


  • Initial release.

  • Supports generating LOC metrics for Ruby source code for a single file at a time.

  • Handles multi-line and single line comments.

  • Handles mixed lines of both code and comments.