Translate to ObjectSpace? (Ruby/Smalltalk)

Here's a cool Smalltalk code snippet:

(Smalltalk allClasses
    select:[:each | each category beginsWith: 'Todo-'])
    inject: 0 into: [:sum :each | sum + each linesOfCode]

It comes from a blog:

What it does is grep the Smalltalk equivalent of ObjectSpace for code
in the author's application. It's pretty easy to do because Smalltalk
objects have categories, and the app uses a simple convention where
everything in it is in a Todo-Xyz category.

Anyway, having grabbed each object, it then sums all the lines of code.

Is this possible in Ruby? I think you'd have to graft something onto Object:

class Object
  def lines_of_code"directory_where_all_my_ruby_stuff_will_be/#{}").lines

Obviously this is pseudocode. Obviously it also depends on a
"convention over configuration" situation, where you can predictably
locate your files. But is it possible? Any ideas for an elegant


Giles Bowkett