How to count lines of code?

I use the free Perl script cloc. Sample usage:

phrogz$ cloc .
     180 text files.
     180 unique files.                                          
      77 files ignored.

http://cloc.sourceforge.net v 1.56  T=1.0 s (104.0 files/s, 19619.0 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Javascript                      29           1774           1338          10456
Ruby                            61            577            185           4055
CSS                             10            118            133            783
HTML                             1             13              3            140
DOS Batch                        2              6              0             19
Bourne Shell                     1              4              0             15
-------------------------------------------------------------------------------
SUM:                           104           2492           1659          15468
-------------------------------------------------------------------------------

Here's a simple solution. It counts the lines of code in your rails project's app folder - CSS, Ruby, CoffeeScript, and all. At the root of your project, run this command:

find ./app -type f | xargs cat | wc -l

EDIT

Read the comments. Then try this instead:

find ./app -type f -name "*.rb" | xargs cat | sed "/^\s*\(#\|$\)/d" | wc -l