# Translate to ObjectSpace? (Ruby/Smalltalk)

**URL:** <https://www.ruby-forum.com/t/translate-to-objectspace-ruby-smalltalk/117300>\
**Category:** Ruby\
**Created:** [October 15, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/translate-to-objectspace-ruby-smalltalk/117300 "2007-10-15T20:33:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giles\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/848f3c/32.png) [@Giles\_B](https://www.ruby-forum.com/u/Giles_B)\
**Post date:** [October 15, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/translate-to-objectspace-ruby-smalltalk/117300/1 "2007-10-15T20:33:51Z")

</div>

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:

[http://blog.teksol.info/2007/10/15/todoapp-on-seaside-in-218-lines](http://blog.teksol.info/2007/10/15/todoapp-on-seaside-in-218-lines)

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  
File.open(“directory\_where\_all\_my\_ruby\_stuff\_will\_be/#{self.name}”).lines  
end  
end

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  
implementation?

–  
Giles B.

Blog: [http://gilesbowkett.blogspot.com](http://gilesbowkett.blogspot.com)  
Portfolio: [http://www.gilesgoatboy.org](http://www.gilesgoatboy.org)  
Tumblelog: [http://giles.tumblr.com/](http://giles.tumblr.com/)
