The expressiveness of ruby…

The web spider writeup continues. I am no longer best friends with red wine after the weekend however.

Speaking of things that are red, I *love* the expressiveness of Ruby. The following is the run method of my Scheduler class, Ruby makes it a piece of cake to understand what is going on here, even without the full context, I think the following is fairly intuitive…

  1. def run
  2.   while not stop?
  3.     if @spider_queue.empty?
  4.       sleep(Timeout)
  5.     else
  6.       # if we haven’t reached the concurrency limit
  7.       # schedule a spider
  8.       if @spider_threads.list.length < ThreadLimit
  9.         @spider_threads.add Thread.new {
  10.           Spider.new.process(remove)
  11.         }
  12.       end
  13.     end
  14.   end
  15.   # join threads
  16.   @spider_threads.list.each {
  17.     |spider_thread| spider_thread.join
  18.   }
  19. end

(For those wondering, yes, it runs in its own thread).

Anyway, this was really only a test of the SyntHihol plugin for Wordpress. It took a bit of setting up as to get Ruby highlighting, I needed the latest version of GeSHi, and I had to turn off TinyMCE, because it kept stealing my indentation :-(

Leave a Reply