[Fwd: translate to ObjectSpace? (Ruby/Smalltalk)]

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[Fwd: translate to ObjectSpace? (Ruby/Smalltalk)]

Reinhard Handl
fyi, cheers, reinhard


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

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 Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/



_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside