Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation to pass commands and data between processes.
-
Open up a new terminal window.
-
Start the Game server. (View Source)
$ ruby game_server.rb druby://localhost:8787
-
Open up a second terminal window.
-
Open an IRB session.
$ irb --prompt simple -I . -r game.rb -r drb/drb
- Connect to the Game server and start a new game.
>> game = Game.new
>> game.server_uri = 'druby://localhost:8787'
- Play the game against the machine. (View Source)
>> game.play('rock')
#=> "Computer plays Paper - You Lose!"