PPL30 Day 28: DRb
Today... err, yesterday, I began looking at Distributed Ruby, or DRb. DRb is a system for allowing Ruby processes to communicate with each other. Really, it's a client/server thing.
This is part of the Peer Pressure Learning 30 series. To learn more about what in the hell that means, see the intro to the series, A Good Time To Learn.
Installation
NOTHING! DRb is included in Ruby 1.8+.

Resources
The DRb Site
I started with what I believe to be the DRb site. In particular, the Introduction to DRb was a pretty straightforward way to get started. If your eyes are up to the task of actually reading the content on this site, the content can be quite informative.

What I Think I Now Know
DRb is a lot of fun to play with, for some reason. I don't really think the DRb site quite does it justice, actually. There are many possibilities. For instance, distributed FizzBuzz!
Server:
1 #!/usr/bin/env ruby 2 # 3 # Server 4 5 require 'drb' 6 7 class FizzBuzz 8 def initialize(range = 1..100) 9 @range = range 10 end 11 12 def range=(home) 13 @range = home 14 end 15 16 def fizzbuzz 17 @range.to_a.map do |num| 18 result = '' 19 result = 'Fizz' if num % 3 == 0 20 result += 'Buzz' if num % 5 == 0 21 result.empty? ? num : result 22 end 23 end 24 end 25 26 DRb.start_service 'druby://:9000', FizzBuzz.new 27 puts DRb.uri 28 29 trap("INT") { DRb.stop_service } 30 DRb.thread.join
Client:
1 #!/usr/bin/env ruby 2 # 3 # Client 4 5 require 'drb' 6 7 DRb.start_service 8 fb = DRbObject.new nil, 'druby://:9000' 9 fb.range = 1..200 10 fb.fizzbuzz.each {|r| puts r }
Of course we need to access FizzBuzz answers from a remote client, right? Place each of those in an executable file (e.g. the server script in server.rb, the client script in client.rb). Then, in one terminal window, run ./server.rb, and in the other run ./client.rb. MAGIC!

I really recommend giving the Introduction to DRb a quick skim, at least. It's really not too complicated, as long as you're awake enough to read it clearly.
I'm so close. I will be doubling up tomorrow, as tomorrow marks the final day of the PPL30. I swear, I'm going to finish. Success is within my grasp, and I shall not allow accolades of such great import slip feebly from my fingers! ... Yup, so, Schema and MacRuby.